Packed vs. holey arrays

JavaScript performance comparison

Revision 12 of this test case created

Info

Same data in the four cases, NaN vs delete vs expanding past size vs undefined.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var packed_array = [0, '1', 2, 3, 4, 5, 6, 7, 8, Number.NaN, 10];
   
    var holey_array1 = [0, '1', 2, 3, 4, 5, 6, 7, 8, Number.NaN, 10];
    delete holey_array1[9];
   
    var holey_array2 = [0, '1', 2, 3, 4, 5, 6, 7, 8];
    holey_array2[10] = 10;
   
    var holey_array3 = [0, '1', 2, 3, 4, 5, 6, 7, 8, undefined, 10];
   
    function packed_sum() {
      var sum = 0;
      for (var i = 0; i < packed_array.length; i++) {
        sum += packed_array[i];
      }
    }
   
    function holey_sum1() {
      var sum = 0;
      for (var i = 0; i < holey_array1.length; i++) {
        sum += holey_array1[i];
      }
    }
   
    function holey_sum2() {
      var sum = 0;
      for (var i = 0; i < holey_array2.length; i++) {
        sum += holey_array2[i];
      }
    }
   
    function holey_sum3() {
      var sum = 0;
      for (var i = 0; i < holey_array3.length; i++) {
        sum += holey_array3[i];
      }
    }
   
};
</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
Packed array sum
packed_sum();
pending…
Holey array sum 1
holey_sum1();
pending…
Holey array sum 2
holey_sum2();
pending…
Holey array sum 3
holey_sum3();
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