Performance of Array vs. Object (v56)

Revision 56 of this benchmark created on


Description

After seeing http://jsperf.com/javascript-associative-vs-non-associative-arrays, I thought the test could be improved.

variant of the original test - read only

Setup

x=3000

Test runner

Ready to run.

Testing in
TestOps/sec
Array1
function sayHello2() {
     AR = function() {
      return [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
    }
}
sayHello2();
for(i=0;i<x;i+=1){
z=AR()[i]
}
 
ready
Array2
function ArrValues(num){
 if(num==='CX')return [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
}
xx=ArrValues('CX')
for(i=0;i<x;i+=1){
xx[i]
}
ready
obj={};
obj.arr= [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];

for(i=0;i<x;i+=1){
 a=obj.arr[i]
}
ready

Revisions

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