Object, Array, Native

JavaScript performance comparison

Test case created by Christopher Wallis

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
objects
function generate(x, y) {
    return {x:x, y: y, unit: 'px'};
}

var s = {x: 5, y: Math.PI, unit: 'px'};
for (var i = 0; i < 10000; i++) {
   s = generate(s.y+1, s.x+1);
}

console.log(s.x + s.y + s.unit);
pending…
array
function generate(x, y) {
    return [x, y,'px']
}

var s = [5, Math.PI,'px'];
for (var i = 0; i < 10000; i++) {
   s = generate(s[1]+1, s[0]+1);
}

console.log(s[0] + s[1] + s[2]);
pending…
objects (mutation)
function generate(x, y, out) {
    out.x = x;
    out.y = y;
    out.unit = 'px'
}

var s = {x: 5, y: Math.PI, unit: 'px'};
for (var i = 0; i < 10000; i++) {
   generate(s.y+1, s.x+1, s);
}

console.log(s.x + s.y + s.unit);
pending…
array (mutation)
function generate(x, y, out) {
    out[0] = x;
    out[1] = y;
    out[2] = 'px';
}

var s = [5, Math.PI,'px'];
for (var i = 0; i < 10000; i++) {
   generate(s[1]+1, s[0]+1, s);
}

console.log(s[0] + s[1] + s[2]);
pending…
number[] (mutation)
function generate(x, y, out) {
    out[0] = x;
    out[1] = y;
}

var s = [5, Math.PI];
for (var i = 0; i < 10000; i++) {
   generate(s[1]+1, s[0]+1, s);
}

console.log(s[0] + s[1] + 'px');
pending…
float32array (mutation)
function generate(x, y, out) {
    out[0] = x;
    out[1] = y;
}

var s = new Float32Array(2);
s[0] = 5;
s[1] = Math.PI;

for (var i = 0; i < 10000; i++) {
   generate(s[1]+1, s[0]+1, s);
}

console.log(s[0] + s[1] + 'px');
pending…

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

0 Comments