new array vs literal (v18)

Revision 18 of this benchmark created by mattdesl on


Setup

var newArray = [];
    
    for (var i=0; i<99; i++) {
        newArray.push(~~(Math.random()*10));
    }
    
    var newArray2 = new Array(100);
    
    for (var i=0; i<99; i++) {
        newArray2[i] = ~~(Math.random()*10);
    }
    
    newArray.push(100);
    newArray2[99] = 100;
    var sum = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Array Literal
newArray.indexOf(100);
ready
new Array()
newArray2.indexOf(100);
ready

Revisions

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