preasad1231231

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script>
function range(n) {
    var arr = [];
    for (var i = 0; i < n; i++) {
        arr.push(i);
    }
    return arr;
}

function rangePreAlloc(n) {
    var arr = new Array(n)
    for (var i = 0; i < n; i++) {
        arr[i] = i;
    }
    return arr;
}
</script>
<script>
Benchmark.prototype.teardown = function() {
    console.log(a); //avoid dead code elimination
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
range pre allocated
var a = rangePreAlloc(2500)
pending…
range
var a = range(2500);
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