LoopWithIfElse

JavaScript performance comparison

Revision 4 of this test case created

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
1
var arr = [1, 2, 3, 4];
var xmin = Number.POSITIVE_INFINITY;
var xmax = Number.NEGTIVE_INIFINITY;
var ymin = Number.POSITIVE_INFINITY;
var ymax = Number.NEGTIVE_INIFINITY;
for (var i = 0; i < arr.length; i+=2){
    var x = arr[i];
    var y = arr[i+1];

    if (x < xmin)  xmin = x;
    if (x > xmax)  xmax = x;
    if (y < ymin)  ymin = y;
    if (y > ymax)  ymax = y;
}
pending…
2
var arr = [1, 2, 3, 4];
var xmin = Number.POSITIVE_INFINITY;
var xmax = Number.NEGTIVE_INIFINITY;
var ymin = Number.POSITIVE_INFINITY;
var ymax = Number.NEGTIVE_INIFINITY;
for (var i = 0; i < arr.length; i+=2){
    var x = arr[i];
    var y = arr[i+1];

    if (x < xmin){
        xmin = x;
    } else if (x > xmax) {
        xmax = x;
    }

    if (y < ymin){
        ymin = y;
    } else if (y > ymax) {
        ymax = y;
    }
}
pending…
3
var arr = [1, 2, 3, 4];
var xmin = Number.MAX_VALUE;
var xmax = -Number.MAX_VALUE;
var ymin = Number.MAX_VALUE;
var ymax = -Number.MAX_VALUE;
for (var i = 0; i < arr.length; i+=2){
    var x = arr[i];
    var y = arr[i+1];

    if (x < xmin){
        xmin = x;
    } else if (x > xmax) {
        xmax = x;
    }

    if (y < ymin){
        ymin = y;
    } else if (y > ymax) {
        ymax = y;
    }
}
pending…
4
var arr = [1, 2, 3, 4];
var xmin = Number.MAX_VALUE;
var xmax = -Number.MAX_VALUE;
var ymin = Number.MAX_VALUE;
var ymax = -Number.MAX_VALUE;
for (var i=0, len = arr.length; i < len; i+=2){
    var x = arr[i];
    var y = arr[i+1];

    if (x < xmin){
        xmin = x;
    } else if (x > xmax) {
        xmax = x;
    }

    if (y < ymin){
        ymin = y;
    } else if (y > ymax) {
        ymax = y;
    }
}
pending…
5
// Jörg Schaper
var arr = [1, 2, 3, 4];
var max = Number.MAX_VALUE;
var min = -max;
var xmin = max;
var xmax = min;
var ymin = max;
var ymax = min;

for (var i = 0, len = arr.length; i < len; i+=2){
    var x = arr[i];
    var y = arr[i+1];

    if (x < xmin){
        xmin = x;
    } else if (x > xmax) {
        xmax = x;
    }

    if (y < ymin){
        ymin = y;
    } else if (y > ymax) {
        ymax = y;
    }
}
pending…
6
// Jörg Schaper
var arr = [1, 2, 3, 4];
var max = Number.MAX_VALUE;
var min = -max;
var xmin = max;
var xmax = min;
var ymin = max;
var ymax = min;
var x;
var y;

for (var i = 0, len = arr.length; i < len; i+=2){
    x = arr[i];
    y = arr[i+1];

    if (x < xmin){
        xmin = x;
    } else if (x > xmax) {
        xmax = x;
    }

    if (y < ymin){
        ymin = y;
    } else if (y > ymax) {
        ymax = y;
    }
}
pending…
7
// Jörg Schaper
var arr = [1, 2, 3, 4];
var num = Number.MAX_VALUE;
var xmin = num;
var xmax = -num;
var ymin = num;
var ymax = -num;
var x;
var y;

for (var i = 0, len = arr.length; i < len; i+=2){
    x = arr[i];
    y = arr[i+1];

    if (x < xmin){
        xmin = x;
    } else if (x > xmax) {
        xmax = x;
    }

    if (y < ymin){
        ymin = y;
    } else if (y > ymax) {
        ymax = y;
    }
}
pending…
5a
// Jörg Schaper
var arr = [1, 2, 3, 4],
max = Number.MAX_VALUE,
min = -max,
xmin = max,
xmax = min,
ymin = max,
ymax = min;

for (var i = 0, len = arr.length; i < len; i+=2){
    var x = arr[i];
    var y = arr[i+1];

    if (x < xmin){
        xmin = x;
    } else if (x > xmax) {
        xmax = x;
    }

    if (y < ymin){
        ymin = y;
    } else if (y > ymax) {
        ymax = y;
    }
}
pending…
7a
// Jörg Schaper
var arr = [1, 2, 3, 4],
num = Number.MAX_VALUE,
xmin = num,
xmax = -num,
ymin = num,
ymax = -num,
x,
y;

for (var i = 0, len = arr.length; i < len; i+=2){
    x = arr[i];
    y = arr[i+1];

    if (x < xmin){
        xmin = x;
    } else if (x > xmax) {
        xmax = x;
    }

    if (y < ymin){
        ymin = y;
    } else if (y > ymax) {
        ymax = y;
    }
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment