language-bench

Matrix multiply

Multiply two dense 256×256 matrices of doubles.

cpu-boundmemory-boundsimdmath

What is measured

Each iteration receives two dense 256×256 matrices of doubles (small integers, varied with the iteration) and multiplies them with the cache-friendly i-k-j loop order. All values are integers, so every sum is exact in floating point and the result cannot depend on summation order, fused multiply-add or vectorisation. All 65,536 entries of the product are hashed afterwards.

Pseudocode

A, B = decode(instance)               # n = 256, untimed
start timer
C = zero matrix n x n
for i in 0..n-1:
    for k in 0..n-1:
        for j in 0..n-1:
            C[i][j] += A[i][k] * B[k][j]
stop timer
hash every entry of C

Reveals: Dense floating-point loops, bounds-check elimination, cache use and auto-vectorisation.

Caveat: Plain nested loops over the language's native array type, no BLAS or SIMD intrinsics: interpreters pay for every element access, while optimising compilers may vectorise the inner loop. Node uses Float64Array, Python lists of floats. R uses %*% (the BLAS linked into R), its idiomatic fast path.

Results (newest release of each language)

Language / buildTime (× vs best)
C 16 · gcc -O3 -march=nativedefault2.0 ms (1.06×)
C 16 · gcc -O33.3 ms (1.75×)
C 16 · gcc -O23.9 ms (2.09×)
Go 1.27 · go builddefault6.6 ms (3.51×)
Go 1.27 · GOAMD64=v3 go build10.9 ms (5.79×)
Python 3.15 · python3default954 ms (505×)

Click a language to see the source code, build flags, every session and how the number was computed.