Clever Make Array

JavaScript performance comparison

Test case created by Michael Geary

Info

Two ways of initializing an array

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Clever Range
function rangeClever( n ) {
    return Array.apply( null, { length: n } ).map( Number.call, Number );
}

for( var n = 50;  n <= 1000;  n += 50 ) {
    rangeClever( n );
}
 
pending…
Simple Range
function rangeSimple( n ) {
    var result = [];
    for( var i = 0;  i < n;  ++i ) {
        result.push(i);
    }
    return result;
}

for( var n = 50;  n <= 1000;  n += 50 ) {
    rangeSimple( n );
}
 
pending…

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

Compare results of other browsers

0 comments

Add a comment