Packed vs. holey arrays
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var packed_array = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9, 'k':10};
var holey_array1 = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9, 'k':10};
delete holey_array1.a;
var holey_array2 = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9, 'k':10};
holey_array2.a = 3;
function packed_sum() {
var sum = 0;
for (var key in packed_array) {
sum += packed_array[key];
}
}
function holey_sum1() {
var sum = 0;
for (var key in holey_array1) {
sum += holey_array1[key];
}
}
function holey_sum2() {
var sum = 0;
for (var key in holey_array2) {
sum += holey_array2[key];
}
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test  Ops/sec  

Packed array sum 

pending… 
Holey array sum 1 

pending… 
Holey array sum 2 

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:
 Revision 1: published
 Revision 2: published
 Revision 3: published
 Revision 4: published by YuCheng Chuang
 Revision 5: published by YuCheng Chuang
 Revision 6: published
 Revision 7: published by Volkan Ozcelik
 Revision 8: published by Hyzhak
 Revision 9: published by NesterChung
 Revision 10: published
 Revision 12: published
 Revision 14: published
 Revision 15: published
 Revision 16: published by JaNo
 Revision 17: published
 Revision 18: published
 Revision 19: published by Stefan Mirea
 Revision 20: published by Max
 Revision 21: published
 Revision 22: published
 Revision 23: published
1 comment
Volkan Ozcelik (revision owner) commented : ∞
Using object literals instead of arrays has the same effect, unsurprisingly.
Comment form temporarily disabled.