μMath Convenience Class Performance Comparison (v2)

Revision 2 of this benchmark created on


Description

A comparison between the performance of μMath's raw functions, convenience methods with self-output, and convenience functions without existing output arrays.

Preparation HTML

<!-- Need to use another script to import modules since the default environment does not support them. -->
<script type="module">
	import Matrix4, { createMatrix4Like, identity, multiply, scale, translate} from "https://esm.sh/@lakuna/umath/Matrix4";
	import { createVector3Like, fromValues } from "https://esm.sh/@lakuna/umath/Vector3";
	import { create as glCreate, multiply as glMultiply, scale as glScale, translate as glTranslate } from "https://esm.sh/gl-matrix/mat4";
	
	// Add imported values to `globalThis` so that they can be accessed outside of this script.
	globalThis.Matrix4 = Matrix4;
	globalThis.createMatrix4Like = createMatrix4Like;
	globalThis.identity = identity;
	globalThis.multiply = multiply;
	globalThis.scale = scale;
	globalThis.translate = translate;
	globalThis.createVector3Like = createVector3Like;
	globalThis.fromValues = fromValues;
	globalThis.glCreate = glCreate;
	globalThis.glMultiply = glMultiply;
	globalThis.glMultiply = glMultiply;
	globalThis.glScale= glScale;
	globalThis.glTranslate= glTranslate;
</script>

Setup

const half = fromValues(0.5, 0.5, 0.5, createVector3Like());
const other = createMatrix4Like();

Test runner

Ready to run.

Testing in
TestOps/sec
Raw Functions
const matrix = createMatrix4Like();
identity(matrix);
translate(matrix, half, matrix);
scale(matrix, half, matrix);
multiply(matrix, other, matrix);
ready
Convenience Methods with Self-Output
const matrix = new Matrix4();
matrix.translate(half, matrix).scale(half, matrix).multiply(other, matrix);
ready
Convenience Methods with New Output
new Matrix4().translate(half).scale(half).multiply(other);
ready
glMatrix
const matrix = glCreate();
glTranslate(matrix, matrix, half);
glScale(matrix, matrix, half);
glMultiply(matrix, matrix, other);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.