push allocated vs dynamic (v25)

Revision 25 of this benchmark created on


Description

is it usefull to pre-allocate the array by setting the last value first when assigning some values ?

Setup

var Bind2 = function(a, b, c) {
      var sum = 0;
      for (var i = 0, l = 3; i < l; i++) {
        sum += 1;
      }
      sum += a + b + c;
      return sum;
    };
    
    var Bind3 = function(a, b, c) {
      var sum = 0;
      for (var i = 0, l = 3; i < l; i++) {
        sum += a;
      }
      return sum;
    };
    
    var Bind = function() {
      var sum = 0;
      for (var i = 0, l = arguments.length; i < l; i++) {
        sum += arguments[i];
      }
      return sum;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Bind2
Bind2(1, 2, 3);
ready
reverse writing
Bind(1, 2, 3);
ready
reverse writing, array allocated with Array constructor
Bind3(1, 2, 3);
ready

Revisions

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