Performance of Array vs. Object

JavaScript performance comparison

Revision 56 of this test case created

Info

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

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    x=3000
};
</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
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]
}
 
pending…
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]
}
pending…
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]
}
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