Array Zero Fill

JavaScript performance comparison

Test case created by Jonathan Larson

Preparation code

<script>
  function t1(len) {
      var arr = new Array(len);
      while (arr-- > 0) {
          arr[len] = 0;
      }
  }
 
  function t2(len) {
      var arr = new Array();
      while (arr-- > 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;
      }
  }
</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…

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