Library comparison
Measuring the same CPU operation with NexusModel, NumPy, and PyTorch.
01What exactly is compared?#
NexusModel is a C++ neural-network layer library, PyTorch a tensor/training framework, and NumPy a numerical array library. We measure their shared CPU float32 GEMM and ReLU forward operations. This does not measure model quality, training capability, or an overall ranking of all APIs.
02NexusModel calls#
Use X=[M,K], W=[N,K], Y=[M,N] with bias=nullptr and the raw linear_forward kernel. This excludes the full Linear module training cache. ReLU uses separate preallocated input/output buffers.
kernels::linear_forward(x.data(), w.data(), nullptr, y.data(), rows, in_features, out_features);kernels::relu(x.data(), y.data(), x.numel());03NumPy calls#
Arrays are float32 and row-major. W.T is prepared before timing; matmul reuses the output buffer via out. maximum implements ReLU. Loaded BLAS backend information is recorded through threadpoolctl in the JSON.
import numpy as npy = np.empty((rows, out_features), dtype=np.float32)wt = w.Tnp.matmul(x, wt, out=y)np.maximum(relu_input, np.float32(0), out=relu_output)04PyTorch calls#
Call torch.set_num_threads(1) and set_num_interop_threads(1) before timing. mm/clamp reuse out buffers within inference_mode. Operations use float32 on CPU; CUDA and autograd are outside this measurement.
import torchtorch.set_num_threads(1)torch.set_num_interop_threads(1)with torch.inference_mode(): torch.mm(x, wt, out=y) torch.clamp(relu_input, min=0, out=relu_output)05Timing and correctness#
Rotate framework order across three rounds. After 20 warmup calls per round, collect 30 samples, each averaging 5 calls. Median and p95 are computed from all 90 values. Every output element is validated against a float64 reference with rtol=1e−4, atol=1e−5. ReLU outputs match exactly. The script refuses to publish failed validation.
06How to interpret results#
This page is the 2026-09-29 study: one thread, small GEMM and ReLU. NexusModel includes C++ call overhead; the others include Python API dispatch. A lowest median in 7 of 9 workloads describes only this table. The evening of 2026-10-21 is separate: GEMM kept avx2-4x16, N=2048 Nexus 330/362/369 GFLOPS, TensorFlow 389. CPU Conv2d was behind PyTorch at 31.6 GFLOPS; Nexus was about 4.9 to 6.8 GFLOPS. Depthwise AVX was ahead of PyTorch 4.93 and TensorFlow 0.688. AVX-512 is not selected on the Ryzen 7 5800H. There is no world ranking.
07Your own measurement#
Run from docs using an isolated Python environment containing NumPy, CPU PyTorch, and threadpoolctl. The script records package versions, thread counts, BLAS backends, and source/executable SHA-256 hashes.
cmake -S examples -B .example-buildcmake --build .example-build --config Releasepython benchmarks/compare_libraries.pynpm run build