Function call overhead (v4)

Revision 4 of this benchmark created by Joe Turner on


Preparation HTML

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

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


  function fun(num) {
    return (num);
  }
</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];
}
ready
Looped function calls
var test2 = 0;

for (var i = 0, n = test.length; i < n; i++) {
  test2 = fun(test[i]);
}
 
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]);
}
ready

Revisions

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