New: Decision Runtime — closed-set judgments for Agent OS. Read the guide →
HazelJS LogoHazelJS

HAZELJS

Comparison

HazelJS Numeric performance against math.js and ml-matrix

HazelJS Numeric was fastest among the three libraries in the 512 × 512 matrix multiplication benchmark. Its median was 73.0 ms, compared with 102.8 ms for ml-matrix and 386.9 ms for math.js.

Updated November 28, 2026

Try it locally

Multiply two matrices and solve a linear system with HazelJS Numeric, math.js, and ml-matrix. The examples use small inputs so you can inspect every result. Use Node.js 20 or later and an npm registry that serves HazelJS 2.2.0.

Jump to benchmark results

mkdir numeric-example
cd numeric-example
npm init -y
npm install @hazeljs/​numeric@2.2.0 mathjs@14.9.1 ml-matrix@6.15.1

Save this as compare.mjs.

import { array, matmul, solve } from '@hazeljs/​numeric';
import { lusolve, multiply } from 'mathjs';
import { Matrix, solve as solveMatrix } from 'ml-matrix';

const a = [[4, 2], [2, 3]];
const b = [[1, 2], [3, 4]];
const rhs = [6, 5];

const hazelA = array(a);
const mlA = new Matrix(a);

console.log('Matrix product A × B');
console.log('HazelJS Numeric', matmul(hazelA, array(b)).tolist());
console.log('math.js', multiply(a, b));
console.log('ml-matrix', mlA.mmul(new Matrix(b)).to2DArray());

console.log('Solution to A × x = rhs');
console.log('HazelJS Numeric', solve(hazelA, array(rhs)).tolist());
console.log('math.js', lusolve(a, rhs).map(([value]) => value));
console.log('ml-matrix', solveMatrix(mlA, Matrix.columnVector(rhs)).to1DArray());
node compare.mjs

Expect a product of [[10, 16], [11, 16]] and a solution of [1, 1], up to floating-point rounding. Change rhs to [8, 11] to try a solve with expected solution [0.25, 3.5].

Benchmark results

On an Apple M3 Max (arm64, Node.js 23.10.0), HazelJS Numeric multiplied two 512 × 512 matrices in 73.0 ms, about 29% less time than ml-matrix and 81% less than math.js in the same test. Numeric also recorded the lowest median for the dot product and linear solve. Measured results JSON

WorkloadSizeHazelJS Numeric (ms)math.js (ms)ml-matrix (ms)
Vector addition5120.0840.080—
Dot product5120.0200.088—
Matrix multiplication512 × 51272.967386.890102.758
Linear solve128 × 1281.0348.5101.071
Reduced SVD48 × 482.931—1.597

Bold shows the lowest measured median in each row. A dash marks a library that the harness did not time for that workload. The solve medians for Numeric and ml-matrix were close on this run.

How the benchmark works

The harness supplies the same float64 values to each library and times repeated calls after imports. The matrix multiplication case prepares each library's inputs in advance. The math.js vector cases include conversion from TypedArrays to JavaScript arrays. The harness checks the benchmark outputs, including the solve against a known solution and the SVD against its expected singular values and reconstruction.

Reproduce this benchmark

Run from a HazelJS source checkout with Node.js 20 or later. The CLI argument sets the main matrix order. The solve and SVD cap their orders separately.

npm ci
npm run build -w @hazeljs/​numeric
cd benchmarks/​numeric
npm ci
npm start -- 512

The run writes medians and runtime information to benchmarks/​numeric/​results/​latest.json. Numeric package guide

FAQ

Where does Numeric lead in this benchmark?
Numeric had the lowest median in the dot product, 512 × 512 matrix multiplication, and 128 × 128 linear solve. These results reflect the tested sizes and runtime.
Which library was quickest for SVD?
ml-matrix had the lower median for the verified 48 × 48 SVD, at 1.597 ms versus 2.931 ms for Numeric.