Array Zero Fill

JavaScript performance comparison

Revision 5 of this test case created

Preparation code

<script>
  function t1(len) {
      var arr = new Array(len);
      while (len-- > 0) {
          arr[len] = 0;
      }
  }
 
  function t2(len) {
      var arr = new Array();
      while (len-- > 0) {
          arr[len] = 0;
      }
  }
 
  function t3(len) {
      var arr = new Array(len);
      for (var i = 0; i < len; i++) {
          arr[i] = 0;
      }
  }
 
  function t4(len) {
      var arr = new Array();
      for (var i = 0; i < len; i++) {
          arr[i] = 0;
      }
  }
 
  function t5(len) {
      var arr = new Array(len);
      for (var i = len; i > 0; i--) {
          arr[i] = 0;
      }
  }
 
  function t6(len) {
      var arr = new Array();
      for (var i = len; i > 0; i--) {
          arr[i] = 0;
      }
  }
 
  function t7(len) {
      var arr = (new Array(len)).forEach(function(x){ return 0; });
  }

  function zero(){ return 0; }
  function t8(len) {
      var arr = (new Array(len)).forEach(zero);
  }
 
  function t9(len) {
      var arr = new Array(len);
      for (var i = 0; i < len; ++i) {
          arr[i] = 0;
      }
  }
 
</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
t1
t1(1000);
pending…
t2
t2(1000);
pending…
t3
t3(1000);
pending…
t4
t4(1000);
pending…
t5
t5(1000);
pending…
t6
t6(1000);
pending…
t7
t7(1000);
pending…
t8
t8(1000);
pending…
t9
t9(1000);
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