DOMMatrix2 (v3)

Revision 3 of this benchmark created on


Setup

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;

Test runner

Ready to run.

Testing in
TestOps/sec
Javascript translateSelf
translateSelf(matrix1, 1, -1);
ready
DOMMatrix translateSelf
domMatrix1.translateSelf(1, -1);
ready
Javascript scaleSelf
scaleSelf(matrix1, 10);
scaleSelf(matrix1, 0.1);
ready
DOMMatrix scaleSelf
domMatrix1.scaleSelf(10);
domMatrix1.scaleSelf(0.1);
ready
Javascript rotateSelf
rotateSelf(matrix1, 45);
rotateSelf(matrix1, -45);
ready
DOMMatrix rotateSelf
domMatrix1.rotateSelf(45);
domMatrix1.rotateSelf(-45);
ready
Javascript multiplySelf
multiplySelf(matrix1, matrix2);
ready
DOMMatrix multiplySelf
domMatrix1.multiplySelf(domMatrix2);
ready

Revisions

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

  • Revision 2: published by Rik Cabanier on
  • Revision 3: published on