Function call overhead (v7)

Revision 7 of this benchmark created by HFLW 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];
}
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
Looped function calls with apply()
var test2 = 0;

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