# DOMMatrix2

## JavaScript performance comparison

Revision 2 of this test case created by Rik Cabanier

## Preparation code

``````

<script>
Benchmark.prototype.setup = function() {
function translateSelf(a, x, y) {
a[4] += a[0] * x + a[2] * y;
a[5] += a[1] * x + a[3] * y;
}

function scaleSelf(a, s) {
a[0] *= s;
a[1] *= s;
a[2] *= s;
a[3] *= s;
}

function rotateSelf(a, angle) {
angle *= Math.PI / 180;
var a0 = a[0],
a1 = a[1],
a2 = a[2],
a3 = a[3],
a4 = a[4],
a5 = a[5],
s = Math.sin(angle),
c = Math.cos(angle);
a[0] = a0 * c + a2 * s;
a[1] = a1 * c + a3 * s;
a[2] = a0 * -s + a2 * c;
a[3] = a1 * -s + a3 * c;
a[4] = a4;
a[5] = a5;
}

function multiplySelf(a, b) {
var a0 = a[0],
a1 = a[1],
a2 = a[2],
a3 = a[3],
a4 = a[4],
a5 = a[5],
b0 = b[0],
b1 = b[1],
b2 = b[2],
b3 = b[3],
b4 = b[4],
b5 = b[5];
a[0] = a0 * b0 + a2 * b1;
a[1] = a1 * b0 + a3 * b1;
a[2] = a0 * b2 + a2 * b3;
a[3] = a1 * b2 + a3 * b3;
a[4] = a0 * b4 + a2 * b5 + a4;
a[5] = a1 * b4 + a3 * b5 + a5;
}

var domMatrix1 = new DOMMatrix();
domMatrix1.a = 3;
domMatrix1.b = -4;
domMatrix1.c = 5;
domMatrix1.d = -6;
domMatrix1.e = 7;
domMatrix1.f = -8;
var domMatrix2 = new DOMMatrix();
domMatrix2.a = 1;
domMatrix2.b = 0;
domMatrix2.c = 0;
domMatrix2.d = 1;
domMatrix2.e = 0;
domMatrix2.f = 0;
var matrix1 = new Float32Array(6);
matrix1[0] = 3;
matrix1[1] = -4;
matrix1[2] = 5;
matrix1[3] = -6;
matrix1[4] = 7;
matrix1[5] = -8;
var matrix2 = new Float32Array(6);
matrix2[0] = 1;
matrix2[1] = 0;
matrix2[2] = 0;
matrix2[3] = 1;
matrix2[4] = 0;
matrix2[5] = 0;
};

</script>
``````

## Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Javascript translateSelf
``````var x = 100000;
while (x--) {
translateSelf(matrix1, 1, -1);
translateSelf(matrix1, -1, 1);
}``````
pending…
DOMMatrix translateSelf
``````var x = 100000;
while (x--) {
domMatrix1.translateSelf(1, -1);
domMatrix1.translateSelf(-1, 1);
}``````
pending…
Javascript scaleSelf
``````var x = 100000;
while (x--) {
scaleSelf(matrix1, 10);
scaleSelf(matrix1, 0.1);
}``````
pending…
DOMMatrix scaleSelf
``````var x = 100000;
while (x--) {
domMatrix1.scaleSelf(10);
domMatrix1.scaleSelf(0.1);
}``````
pending…
Javascript rotateSelf
``````var x = 100000;
while (x--) {
rotateSelf(matrix1, 45);
rotateSelf(matrix1, -45);
}``````
pending…
DOMMatrix rotateSelf
``````var x = 100000;
while (x--) {
domMatrix1.rotateSelf(45);
domMatrix1.rotateSelf(-45);
}``````
pending…
Javascript multiplySelf
``````var x = 100000;
while (x--) {
multiplySelf(matrix1, matrix2);
}``````
pending…
DOMMatrix multiplySelf
``````var x = 100000;
while (x--) {
domMatrix1.multiplySelf(domMatrix2);
}``````
pending…

## Revisions

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