Function call cost (v5)

Revision 5 of this benchmark created on


Description

Examines the cost of a simple function call.

Setup

function foo(a, b, c) {
      if (a === "a") { // a will never be "a"
        throw "Error";
      }
    }
    
    var array = [];
    (function() {
      var index = 100;
      while (index) {
        array.push(index);
        --index;
      }
    })();
    
    var index;

Test runner

Ready to run.

Testing in
TestOps/sec
No call
for (index = 0; index < array.length; ++index) {
  if (array[index] === "a") { // will never happen
    throw "Error";
  }
}
ready
With call
for (index = 0; index < array.length; ++index) {
  foo(array[index], index, array);
}
ready
forEach (ES5 browsers only)
array.forEach(foo);
ready
forEach (inline function, ES5 browsers only)
array.forEach(function(a, b, c) {
  if (a === "a") { // will never happen
    throw "Error";
  }
});
ready
for (index = 0; index < array.length; ++index) {
  if (false) {
    throw "Error";
  }
}
ready
array.forEach(function() {
  if (false) { // will never happen
    throw "Error";
  }
});
ready

Revisions

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

  • Revision 1: published by T.J. Crowder on
  • Revision 5: published on
  • Revision 9: published by Dmitry Kulikov on