array literal with push versus array constuctor with length and assignment

JavaScript performance comparison

Test case created by canon

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function constructorLengthAndAssignment() {
      var r = Math.random,
          o = new Array(64);
      for (var i = 0; i < 64; i++) {
        o[i] = String.fromCharCode(r() * 2 | 0 ? r() * 10 | 48 : r() * 26 | (r() * 2 | 0 ? 65 : 97));
      }
      return o.join('');
    };
   
    function literalAndPush() {
      var r = Math.random,
          o = [];
      for (var i = 0; i < 64; i++) {
        o.push(String.fromCharCode(r() * 2 | 0 ? r() * 10 | 48 : r() * 26 | (r() * 2 | 0 ? 65 : 97)));
      }
      return o.join('');
    };
};
</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
constructorLengthAndAssignment
constructorLengthAndAssignment();
pending…
literalAndPush
literalAndPush();
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment