There are many strong libraries for numerical computing. Most of them are written in C, C++, and Fortran, with excellent Rust wrappers and Python bindings on top.
Where Rust is especially convenient is dependency management and reproducible benchmarking, making it a good place to line up apples-to-apples comparisons across native crates and their Python bindings. NumWars exists for the same reason StringWars exists for StringZilla: to compare NumKong against mainstream CPU and GPU stacks on the workloads it was built for, including:
ndarrayandnalgebrafor dense tensor and linear algebra kernels.faerandmatrixmultiplyfor GEMM-like Rust baselines.geofor geographic distances.polarsand reduction-heavy analytics workloads.NumPy,SciPy, andscikit-learnon Python.- cuBLAS and cuBLASLt through
cudarcin Rust, andPyTorchandCuPyin Python, for the GPU rows.
Of course, the APIs and internal kernels of those projects are different.
So this repository focuses on the workload families NumKong was designed for and compares their effective throughput using the native unit for each operation family instead of forcing everything into fake global ops/s.
Important
The charts below were measured single-threaded on one CPU core.
Each suite README keeps its reference numbers per machine, single-threaded on CPUs, and the dots, similarities, attention and shapes READMEs add GPU sections.
They will vary with CPU model, compiler flags, BLAS backend, and problem size.
Rebuild and rerun on your own hardware before treating them as absolute.
NumKong packed dots are mixed-precision by design. i8 inputs produce i32 outputs. bf16 and f16 inputs produce f32 outputs. f32 inputs produce f64 outputs. The mainstream baselines shown here keep f32 β f32. Every product below is C = A Γ Bα΅ with A of 1024Γ1536 and B of 128Γ1536. Compared to Rust projects, it means:
NumKong:
numkong::dots_packed_into i8 β i32 ββββββββββββββββββββββββββββββββββββ 2,713.30 GSO/s
numkong::dots_packed_into bf16 β f32 ββββββββββββββββββ 1,324.80 GSO/s
numkong::dots_packed_into f16 β f32 βββββββββββββββββ 1,265.00 GSO/s
numkong::dots_packed_into f32 β f64 β 51.67 GSO/s
Alternatives:
ndarray::dot f32 β f32 ββ 138.23 GSO/s
matrixmultiply::sgemm f32 β f32 ββ 122.94 GSO/s
nalgebra::gemm f32 β f32 ββ 110.77 GSO/s
faer::linalg::matmul::matmul f32 β f32 ββ 90.39 GSO/s
Compared to Python:
NumKong:
numkong.dots_packed i8 β i32 ββββββββββββββββββββββββββββββββββββββββββββ 1,559.06 GSO/s
numkong.dots_packed bf16 β f32 βββββββββββββββββββββββ 795.88 GSO/s
numkong.dots_packed f16 β f32 ββββββββββββββββββββββ 765.92 GSO/s
numkong.dots_packed f32 β f64 β 31.23 GSO/s
Alternatives:
numpy.matmul f32 β f32 ββββ 136.24 GSO/s
See dots/README.md for details.
Single-pair vector kernels at 1536 dimensions. This lists Dot products and true Euclidean distances measurements into one throughput-sorted view. NumKong keeps its mixed-precision promotions, while the baseline libraries mostly stay in their input type.
Compared to Rust projects, it means:
NumKong:
numkong::Dot::dot u8 β u32 βββββββββββββββββββββββββββββββββββββ 59.85 GSO/s
numkong::Dot::dot i8 β i32 ββββββββββββββββββββββββββββββββββ 54.49 GSO/s
numkong::Euclidean::euclidean u8 β f32 ββββββββββββββββββββββββββ 41.95 GSO/s
numkong::Euclidean::euclidean i8 β f32 ββββββββββββββββββββββββ 38.69 GSO/s
numkong::Dot::dot bf16 β f32 βββββββββββββ 21.00 GSO/s
numkong::Euclidean::euclidean bf16 β f32 ββββββββββ 15.28 GSO/s
numkong::Dot::dot f32 β f64 βββββ 8.20 GSO/s
numkong::Euclidean::euclidean f32 β f64 βββββ 7.40 GSO/s
Alternatives:
cblas_sdot f32 β f32 βββββββββββββββββββββ 33.40 GSO/s
ndarray::dot f32 β f32 ββββββββββββββββββββ 32.17 GSO/s
nalgebra::dot f32 β f32 ββββββββββββ 18.60 GSO/s
ndarray::norm f32 β f32 βββββββ 9.98 GSO/s
nalgebra::norm f32 β f32 βββββ 8.28 GSO/s
Compared to Python:
NumKong:
numkong.euclidean u8 β f64 βββββββββββββββββββββββββββββββββββββββββββββββββββ 6.23 GSO/s
numkong.euclidean i8 β f64 βββββββββββββββββββββββββββββββββββββββββββββββββββ 6.23 GSO/s
numkong.dot i8 β f64 βββββββββββββββββββββββββββββββββββββββββββββββββββ 6.19 GSO/s
numkong.dot u8 β f64 βββββββββββββββββββββββββββββββββββββββββββββββββ 5.98 GSO/s
numkong.angular u8 β f64 βββββββββββββββββββββββββββββββββββββββββββββββββ 5.89 GSO/s
numkong.angular i8 β f64 ββββββββββββββββββββββββββββββββββββββββββββββ 5.56 GSO/s
numkong.euclidean f32 β f64 ββββββββββββββββββββββββββββββ 3.56 GSO/s
numkong.dot f64 β f64 ββββββββββββββββββββββββ 2.91 GSO/s
Alternatives:
numpy.dot f32 β f32 βββββββββββββββββββββββββββββ 3.47 GSO/s
numpy.dot f64 β f64 βββββββββββββββββββββββββ 2.95 GSO/s
See similarity/README.md for details.
Matrix-vs-matrix comparisons at 2048 rows by 1536 dimensions. These are the packed many-to-many siblings of the pairwise spatial kernels above. The merged lists below include angular and euclidean metrics, and the headline unit is GSO/s.
Compared to Rust projects, it means:
NumKong:
numkong::Tensor::euclideans_packed_into u8 β f32 ββββββββββββββββββββββββββ 672.55 GSO/s
numkong::Tensor::euclideans_packed_into i8 β f32 ββββββββββββββββββββββββββ 671.80 GSO/s
numkong::Tensor::angulars_packed_into i8 β f32 βββββββββββββββββββββββββ 624.33 GSO/s
numkong::Tensor::angulars_packed_into u8 β f32 ββββββββββββββββββββββββ 622.16 GSO/s
numkong::Tensor::angulars_packed_into bf16 β f32 βββββββββββββββ 382.95 GSO/s
numkong::Tensor::euclideans_packed_into bf16 β f32 βββββββββββββββ 381.91 GSO/s
numkong::Tensor::euclideans_packed_into f32 β f64 β 25.22 GSO/s
numkong::Tensor::angulars_packed_into f32 β f64 β 23.86 GSO/s
Alternatives:
ndarray::dot euclidean f32 β f32 ββββ 84.15 GSO/s
ndarray::dot angular f32 β f32 ββββ 81.83 GSO/s
nalgebra::DMatrix::mul euclidean f32 β f32 ββ 37.88 GSO/s
nalgebra::DMatrix::mul angular f32 β f32 ββ 30.30 GSO/s
Compared to Python through SciPy cdist:
NumKong:
numkong.euclideans_packed i8 β f32 ββββββββββββββββββββββββββββ 630.44 GSO/s
numkong.angulars_packed i8 β f32 βββββββββββββββββββββββββββ 594.14 GSO/s
numkong.euclideans_packed u8 β f32 ββββββββββββββββββββββββ 524.71 GSO/s
numkong.angulars_packed u8 β f32 ββββββββββββββββββββββ 489.43 GSO/s
numkong.euclideans_packed f32 β f64 β 15.27 GSO/s
numkong.angulars_packed f32 β f64 β 15.23 GSO/s
Alternatives:
scipy.spatial.distance.cdist euclidean f32 β f64 β 3.39 GSO/s
scipy.spatial.distance.cdist cosine f32 β f64 β 3.06 GSO/s
See similarities/README.md for details.
Bandwidth-sensitive elementwise kernels over 2048 elements, covering sum, scale and fused multiply-add. Sum shown as representative sample. In Rust:
NumKong:
numkong::EachSum::each_sum f16 β f16 βββββββββββββββββββββββββββββββββββββββββ 174.35 GB/s
numkong::EachSum::each_sum f32 β f32 ββββββββββββββββββββββββββββββββββββββββ 167.83 GB/s
numkong::EachSum::each_sum i8 β i8 βββββββββββββββββββββββββββββ 121.56 GB/s
Alternatives:
baseline_sum f32 β f32 βββββββββββββββββββββββββββββββ 131.65 GB/s
nalgebra::add_to f32 β f32 βββββββββββββββββββββββββββββ 120.11 GB/s
ndarray::Zip::for_each f32 β f32 ββββββββββββββββββββββββββββ 117.70 GB/s
In Python:
numpy.add f64 β f64 βββββββββββββββββββββββββββββββββββββββββββββββββββββββ 60.20 GB/s
numpy.add f32 β f32 βββββββββββββββββββββββββββββββββββββββββββββββ 51.49 GB/s
numkong.add f64 β f64 ββββββββββββββββββββββββββββββββββββββββββββββ 50.35 GB/s
numkong.add f32 β f32 βββββββββββββββββββββββββββββββββββββββ 42.06 GB/s
numkong.add f16 β f16 βββββββββββββββββββββ 22.95 GB/s
numpy.add i8 β i8 βββββββββββββββ 16.19 GB/s
numkong.add i8 β i8 ββββββββββββ 12.19 GB/s
numkong.add bf16 β bf16 ββ 2.07 GB/s
numpy.add f16 β f16 ββ 1.60 GB/s
See each/README.md for details.
Horizontal reductions over 2048 elements.
The suite covers sum, min-max and row-wise L2 norms; the Rust sum rows return the sum and the sum of squares together, as NumKong's reduce_moments does.
In Rust:
ndarray::sum β ndarray::dot f64 β f64 ββββββββββββββββββββββββββββββ 51.15 GB/s
numkong::ReduceMoments::reduce_moments f32 β f64 ββββββββββββββββββββββββββββββ 50.80 GB/s
numkong::ReduceMinMax::reduce_minmax f64 β f64 ββββββββββββββββββββββββββββββ 50.17 GB/s
argminmax::ArgMinMax f32 β f32 ββββββββββββββββββββββββββββ 46.51 GB/s
numkong::ReduceMinMax::reduce_minmax f32 β f32 βββββββββββββββββββββββββββ 46.11 GB/s
ndarray::sum β ndarray::dot f32 β f32 βββββββββββββββββββββ 34.53 GB/s
polars::ChunkedArray::min/max f32 β f32 βββββββββββββββββ 27.98 GB/s
numkong::ReduceMoments::reduce_moments f64 β f64 βββββββββββββββββ 27.87 GB/s
baseline_moments f32 β f32 βββββ 7.29 GB/s
baseline_minmax f32 β f32 βββ 3.91 GB/s
Row-wise L2 norms over a 2048Γ1536 matrix:
ndarray::dot f64 β f64 ββββββββββββββββββββββββββββββββ 26.88 GB/s
ndarray::dot f32 β f32 ββββββββββββββββββββββββββββββββ 26.54 GB/s
numkong::MomentsOps::norm_axis_into f32 β f64 βββββββββββββββββββββββββββββ 23.88 GB/s
numkong::MomentsOps::norm_axis_into bf16 β f64 βββββββββββββββββββββββββββ 22.22 GB/s
numkong::MomentsOps::norm_axis_into f64 β f64 βββββββββββββββββββββ 17.31 GB/s
baseline_row_norms_float f64 β f64 βββββββββββββββββ 13.75 GB/s
baseline_row_norms_float f32 β f32 βββββββ 5.65 GB/s
In Python over 2048 elements, and over the same 2048Γ1536 matrix for the norms:
numkong.minmax f64 β f64 βββββββββββββββββββββββββββββββββββββββββ 32.40 GB/s
numkong.sum f32 β f64 ββββββββββββββββββββββββββββββββββββββββ 31.21 GB/s
numkong.sum f64 β f64 ββββββββββββββββββββββββββββββ 23.72 GB/s
numkong.norm f32 β f64 βββββββββββββββββββββββββββββ 22.52 GB/s
numkong.minmax f32 β f32 ββββββββββββββββββββββββββββ 22.18 GB/s
numkong.norm f64 β f64 ββββββββββββββββββββββ 16.99 GB/s
numkong.sum i8 β i64 ββββββββββββββββ 12.29 GB/s
numkong.sum u8 β u64 βββββββββββββββ 11.94 GB/s
numpy.sum f64 β f64 βββββββββββββ 10.21 GB/s
numpy.argmin β numpy.argmax f64 β f64 βββββββββββ 8.25 GB/s
numpy.linalg.norm f64 β f64 ββββββββββ 7.69 GB/s
numpy.linalg.norm f32 β f32 ββββββββ 6.39 GB/s
numpy.sum f32 β f32 βββββββ 5.29 GB/s
numpy.argmin β numpy.argmax f32 β f32 ββββββ 4.83 GB/s
numpy.sum i8 β i64 β 0.85 GB/s
See reduce/README.md for details.
ColBERT-style late interaction with 1024 query vectors, 128 document vectors, and 1536 dimensions. NumKong promotes f32 β f64 here as well, while ndarray stays in f32. In Rust:
NumKong:
numkong::MaxSimPackedMatrix::score bf16 β f32 βββββββββββββββββββββββββββββ 1,271.00 GSO/s
numkong::MaxSimPackedMatrix::score f16 β f32 ββββ 172.87 GSO/s
numkong::MaxSimPackedMatrix::score f32 β f64 βββ 95.08 GSO/s
Alternatives:
ndarray::dot f32 β f32 ββββ 149.58 GSO/s
Compared to Python:
NumKong:
numkong.maxsim_packed bf16 β f32 ββββββββββββββββββββββββββββββββββββββββββ 1,137.65 GSO/s
numkong.maxsim_packed f16 β f32 βββββββ 171.16 GSO/s
numkong.maxsim_packed f32 β f64 ββββ 103.77 GSO/s
Alternatives:
numpy.matmul f32 β f32 ββββββ 141.11 GSO/s
See maxsim/README.md for details.
Many-to-many distances from 1024 row points to 128 column points, each set packed once outside the timed loop.
The unit is MP/s, or million coordinate pairs per second.
The merged lists below include Haversine distances on the IUGG mean sphere and Vincenty distances on the WGS-84 ellipsoid, where geo and pyproj answer with Karney's geodesic solver.
Compared to Rust projects, it means:
NumKong:
numkong::HaversinesPackedMatrix::haversines f64 β f64 ββββββββββββββββββββββββ 295.64 MP/s
numkong::VincentysPackedMatrix::vincentys f64 β f64 ββ 23.46 MP/s
Alternatives:
geo::Haversine f64 β f64 ββ 24.06 MP/s
geo::Geodesic f64 β f64 1.39 MP/s
Compared to Python and its alternatives:
NumKong:
numkong.haversines_packed f64 β f64 βββββββββββββββββββββββ 294.42 MP/s
numkong.vincentys_packed f64 β f64 ββ 24.12 MP/s
Alternatives:
numpy_haversines f64 β f64 βββ 31.73 MP/s
sklearn.metrics.pairwise.haversine_distances f64 β f64 ββ 17.72 MP/s
pyproj.Geod.inv f64 β f64 1.24 MP/s
See geospatial/README.md for details.
Many-to-many distances between 8 row and 8 column clouds of 32 3D points each, with the correspondence-free Chamfer, Hausdorff, Wasserstein-Procrustes and Gromov-Wasserstein distances that replaced mesh alignment. Every distance takes the best of the 8 sign flips of each cloud's principal axes, and the baselines search the same flips. The unit is MP/s, or million cloud pairs per second, and the lists below cover f32 clouds. In Rust:
NumKong:
numkong::ShapesPackedMatrix::chamfers_on f32 β f64 ββββββββββββββ 0.8206 MP/s
numkong::ShapesPackedMatrix::hausdorffs f32 β f64 βββββββββββ 0.6521 MP/s
numkong::ShapesPackedMatrix::wassersteinprocrustes_on f32 β f64 β 0.0074 MP/s
numkong::ShapesPackedMatrix::gromovwassersteins_on f32 β f64 0.0045 MP/s
Alternatives:
baseline_distance chamfers f32 β f64 ββ 0.0928 MP/s
baseline_distance hausdorffs f32 β f64 ββ 0.0913 MP/s
baseline_wasserstein_procrustes f32 β f64 0.0028 MP/s
Compared to Python and its alternatives:
NumKong:
numkong.chamfers_packed f32 β f64 βββββββββββββββββββββββββββββββ 0.8114 MP/s
numkong.hausdorffs_packed f32 β f64 βββββββββββββββββββββββββ 0.6503 MP/s
numkong.wassersteinprocrustes_packed f32 β f64 β 0.0070 MP/s
numkong.gromovwassersteins_packed f32 β f64 β 0.0039 MP/s
Alternatives:
scipy.spatial.cKDTree hausdorffs f32 β f64 β 0.0037 MP/s
scipy.spatial.cKDTree chamfers f32 β f64 β 0.0036 MP/s
ot.gromov.gromov_wasserstein2 f32 β f64 0.0003 MP/s
scipy.optimize.linear_sum_assignment f32 β f64 0.0005 MP/s
See shapes/README.md for details.
Every Rust benchmark is a Criterion harness behind a Cargo feature gate. Run one suite at a time or all at once:
# One suite
RUSTFLAGS="-C target-cpu=native" \
cargo bench --features bench_similarity --bench bench_similarity
# All suites
RUSTFLAGS="-C target-cpu=native" \
cargo bench --features allTuning knobs (environment variables):
| Variable | Default | Meaning |
|---|---|---|
NUMWARS_FILTER |
Regex over benchmark names, or a substring if not a regex | |
NUMWARS_SEED |
42 | 32-bit seed for random inputs, or random |
NUMWARS_WARMUP |
1s | Warm-up per benchmark, like 200ms or 1s |
NUMWARS_TIME_LIMIT |
10s | Measurement time per benchmark, like 200ms or 10s |
NUMWARS_BATCH_PER_CORE |
2048 | Items per call, times the threads: elements, rows, points |
NUMWARS_THREADS |
1 | Threads for NumKong and competitors, 0 for all cores |
NUMWARS_DIMS |
1536 | Vector length |
NUMWARS_DIMS_HEIGHT |
1024 | Rows of C = A Γ Bα΅ in GEMM-shaped suites |
NUMWARS_DIMS_WIDTH |
128 | Columns of C = A Γ Bα΅ in GEMM-shaped suites |
NUMWARS_DIMS_DEPTH |
1536 | Shared dimension of A and B in GEMM-shaped suites |
NUMWARS_SHAPE_POINTS |
32 | Points per cloud in the shapes suite |
NUMWARS_DEVICES |
cuda:0 | CUDA devices in GPU suites, like cuda:0,cuda:1 |
NUMWARS_SAMPLE_SIZE |
50 | Criterion samples per benchmark, Rust only |
NUMWARS_OUTPUT |
table | Human-readable table or machine-readable json, Python |
NUMWARS_SCIPY |
false | Whether the Python similarity suite also times SciPy |
NUMWARS_DEVICES is read by the suites that put rows on a GPU, dots, similarities, attention and shapes, and any other suite refuses it rather than ignoring it.
Each selected device gets its own rows, named after its ordinal as in <cuda:1>, and a device named in the variable that cannot be opened stops the run.
Without the variable, a GPU build puts rows on device zero when the machine has one.
Every GPU row synchronizes inside its timed region, and checks its first round against NumKong's CPU kernel on the leading rows before timing.
The suite defaults are CPU-sized, so GPU runs usually raise the shapes and filter on cuda, which only GPU rows carry.
In Rust, the cuda feature adds those rows, building NumKong's CUDA kernels with nvcc, or linking the CMake tree NUMKONG_LIBRARY_DIR names, and loading cuBLAS and cuBLASLt from the CUDA 13 toolkit at run time:
NUMWARS_DEVICES=cuda:0 NUMWARS_FILTER=cuda \
NUMWARS_DIMS_HEIGHT=16384 NUMWARS_DIMS_WIDTH=16384 NUMWARS_DIMS_DEPTH=16384 \
cargo bench --features "bench_dots cuda" --bench bench_dotsNumKong's Rust verbs dispatch to the CPU, so these rows call its exported C dispatch with the device's capabilities and stream, over operands in its UnifiedAllocator.
In Python, they need NumKong built with -C cmake.define.NUMKONG_CUDA_ARCH=<code>, like 120f for SM120, PyTorch's CUDA wheels to hold the operands, and optionally CuPy:
pip install --force-reinstall --no-cache-dir \
"numkong @ git+https://github.com/ashvardanian/NumKong@e00a0f8089a90170db1ea8ae5d54c75aee247c10" \
-C cmake.define.NUMKONG_CUDA_ARCH=120f
pip install -e ".[cuda]" --extra-index-url https://download.pytorch.org/whl/cu130
NUMWARS_DEVICES=cuda:0 NUMWARS_FILTER=cuda NUMWARS_BATCH_PER_CORE=16384 python similarities/bench.pyThe Python suites read the same variables, and take no flags. An empty variable counts as unset, and a value that does not parse stops the run.
Install with uv and run any suite directly:
uv run --with "numkong @ git+https://github.com/ashvardanian/NumKong@e00a0f8089a90170db1ea8ae5d54c75aee247c10" \
--with "numpy,scipy,tabulate,ml_dtypes" python similarity/bench.pyOr install all extras and run from the repo root:
pip install -e ".[similarity,each,dots,geospatial,shapes,reduce,similarities,maxsim,attention]"
python dots/bench.py
python similarities/bench.py- similarity/README.md
- similarities/README.md, with GPU rows
- dots/README.md, with GPU rows
- each/README.md
- reduce/README.md
- maxsim/README.md
- geospatial/README.md
- shapes/README.md
- attention/README.md, with GPU rows
Apache 2.0. See LICENSE.