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.0043 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.0007 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.