Function call overhead (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script>
  var test = [],
      limit = 100000;

  for (var i = 0; i < limit; i++) {
    test.push(Math.random());
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Function call to loop
var test2 = 0;


for (var i = 0, n = test.length; i < n; i++) {
  test2 = test[i];
  var x = 1;
}
ready
Looped function calls
var test2 = 0;

for (var i = 0, n = test.length; i < n; i++) {
  test2 = fun(test[i]);
}

function fun(num) {
  return (num);
}
ready
Looped function calls with caching
var test2 = 0;
var testFunc = fun;

for (var i = 0, n = test.length; i < n; i++) {
  test2 = testFunc(test[i]);
}

function fun(num) {
  return (num);
}
ready

Revisions

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