This page benchmarks the performance of a collection of matrix libraries most of which are intended for use with WebGL:
glMatrix (v3.4.0, 2023-4-11),
mjs (rev 16, 2010-12-15),
CanvasMatrix,
EWGL_math (rev 32, 2011-03-15),
the math utilities in Google's Closure (svn rev: 1364, 2011-11-3),
tdl (commit: 59d484f, 2011-06-03),
twgl.js (v3.3.0, 2017-05-05),
wgpu-matrix (v1.0.0, 2023-04-1), and
Sylvester (v0.1.3, 2007-07-05).
Benchmarks for each library are run in an iframe. Results measure millions of iterations per second of the target operation.
Library | Multiplication | Translation | Scaling | Rotation (Arbitrary axis) | Rotation (X axis) | Transpose | Inverse | Vector Transformation | Average |
twgl-math-native | 24.82 | 93.05 | 110.37 | | | | | | 76.08 |
twgl-float64 | 29.71 | 77.20 | 93.93 | | | | | | 66.95 |
twgl-math | 24.03 | 78.13 | 94.61 | | | | | | 65.59 |
twgl-native | 24.84 | 64.79 | 99.45 | | | | | | 63.03 |
twgl | 23.99 | 62.67 | 78.52 | | | | | | 55.06 |
glMatrix-native | 21.13 | 38.39 | 46.30 | | | | | | 35.28 |
glMatrix | 21.02 | 38.23 | 46.16 | | | | | | 35.14 |
glMatrix-float64 | 21.06 | 38.23 | 45.99 | | | | | | 35.09 |
Adapted by Stephen Bannasch from the benchmarks Brandon Jones created in his glmatrix library.
Additional improvements by Gregg Tavares.
Sylvester benchmarks by Felix E. Klee.
JavaScript Plotting library: Flotr;
Sortable Table by Andrew Tetlaw.
The source code for these benchmarks can be found here on github. Pull requests quite welcome!
=============================================
Multiplication
=============================================
twgl-native - Avg: 24839773 iterations per second, Min: 22897010 iterations per second, Max: 25303333 iterations per second
twgl-math-native - Avg: 24816000 iterations per second, Min: 23000000 iterations per second, Max: 25283333 iterations per second
twgl-math - Avg: 24027000 iterations per second, Min: 21626666 iterations per second, Max: 24430000 iterations per second
twgl-float64 - Avg: 29710333 iterations per second, Min: 27403333 iterations per second, Max: 30360000 iterations per second
twgl - Avg: 23990000 iterations per second, Min: 21686666 iterations per second, Max: 24373333 iterations per second
glMatrix-native - Avg: 21130246 iterations per second, Min: 19846666 iterations per second, Max: 21292358 iterations per second
glMatrix-float64 - Avg: 21058333 iterations per second, Min: 19283333 iterations per second, Max: 21356666 iterations per second
glMatrix - Avg: 21017333 iterations per second, Min: 19436666 iterations per second, Max: 21300000 iterations per second
=============================================
Translation
=============================================
twgl-native - Avg: 64794333 iterations per second, Min: 60056666 iterations per second, Max: 65516666 iterations per second
twgl-math-native - Avg: 93049983 iterations per second, Min: 82353333 iterations per second, Max: 94463333 iterations per second
twgl-math - Avg: 78134000 iterations per second, Min: 71136666 iterations per second, Max: 79183333 iterations per second
twgl-float64 - Avg: 77199333 iterations per second, Min: 70790000 iterations per second, Max: 78013333 iterations per second
twgl - Avg: 62673333 iterations per second, Min: 57926666 iterations per second, Max: 63370000 iterations per second
glMatrix-native - Avg: 38393666 iterations per second, Min: 37133333 iterations per second, Max: 38716666 iterations per second
glMatrix-float64 - Avg: 38230000 iterations per second, Min: 35993333 iterations per second, Max: 38646666 iterations per second
glMatrix - Avg: 38233666 iterations per second, Min: 36013333 iterations per second, Max: 38736666 iterations per second
=============================================
Scaling
=============================================
twgl-native - Avg: 99449000 iterations per second, Min: 93096666 iterations per second, Max: 100400000 iterations per second
twgl-math-native - Avg: 110371666 iterations per second, Min: 101863333 iterations per second, Max: 112343333 iterations per second
twgl-math - Avg: 94610000 iterations per second, Min: 86433333 iterations per second, Max: 95723333 iterations per second
twgl-float64 - Avg: 93928666 iterations per second, Min: 87810000 iterations per second, Max: 95026666 iterations per second
twgl - Avg: 78515333 iterations per second, Min: 73263333 iterations per second, Max: 79846666 iterations per second
glMatrix-native - Avg: 46302000 iterations per second, Min: 43576666 iterations per second, Max: 46750000 iterations per second
glMatrix-float64 - Avg: 45985666 iterations per second, Min: 42763333 iterations per second, Max: 46526666 iterations per second
glMatrix - Avg: 46160333 iterations per second, Min: 43230000 iterations per second, Max: 46746666 iterations per second