Javascript Range Tests

JavaScript performance comparison

Test case created by Justin

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
Range Type 1
Array.apply(null, Array(31)).map(function (_, i) {return i;});
pending…
Range Type 2
var range = function(start, end, step) {
    var range = [];
    var typeofStart = typeof start;
    var typeofEnd = typeof end;

    if (step === 0) {
        throw TypeError("Step cannot be zero.");
    }

    typeof step == "undefined" && (step = 1);

    if (end < start) {
        step = -step;
    }
        while (step > 0 ? end >= start : end <= start) {
            range.push(start);
            start += step;
        }
    return range;

}
range(0,31, 1);
pending…
Range Type 3
Array.prototype.range= function(a, b, step){
    var A= [];
        A[0]= a;
        step= step || 1;
        while(a+step<= b){
            A[A.length]= a+= step;
        }
    return A;
}
myarr = [];
myarr.range(0,31,1);
pending…
Range Type 4
function range(start, stop, step){
  var a = []; a[start], b=start;
  while(b<stop){b+=step;a.push(b)}
  return a;
};
range(0,31,1);
pending…
Range Type 5
function range(lowEnd,highEnd){
var arr = [],
c = highEnd - lowEnd + 1;
while ( c-- ) {
 arr[c] = highEnd--
}
return arr;
}
range(0,31);
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.

0 Comments