Function call cost

Benchmark created by T.J. Crowder on


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

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