dynamic or fixed

JavaScript performance comparison

Revision 3 of this test case created

Info

Testing dynamic arrays vs fixed length arrays, inspiration from Alex Gaynor's talk: https://speakerdeck.com/alex/why-python-ruby-and-javascript-are-slow

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function square(n) {
      var ret = [];
      for (var i=0; i<n; i++) {
        ret[i] = i*i;
      }
      return ret;
    }
   
    function square2(n) {
      var ret = new Array(n);
      for (var i=0; i<n; i++) {
        ret[i] = i*i;
      }
      return ret;
    }
   
    function square3(n) {
        var buffer = new ArrayBuffer(n*4);
        var int32View = new Uint32Array(buffer);
        for (var i=0; i<n; i++) {
            int32View[i] = i*i;
        }
        return int32View;
    }
};
</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
dynamic length
square(100);
pending…
fixed lenght
square2(100);
pending…
typed arrays
square3(100);
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