direct vs call vs apply (v2)

Revision 2 of this benchmark created by isaacs on


Preparation HTML

<script>
  function calc(a, b, c) {
   return Math.sqrt((a * b / c) + 10)
  }
  var obj = {
   calc: calc
  }
  
  function Ctor() {}
  Ctor.prototype.calc = calc
  var cobj = new Ctor()
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
direct
obj.calc(5, 7, 8);
ready
call
obj.calc.call(obj, 5, 8, 7);
ready
apply
obj.calc.apply(obj, [5, 8, 7]);
ready
direct ctor
cobj.calc(5, 7, 8)
ready
call ctor
cobj.calc.call(cobj, 5, 7, 8)
ready
apply ctor
cobj.calc.apply(cobj, [5, 8, 7]);
ready
noprop direct
calc(5, 7, 8)
ready
noprop call
calc.call(obj, 5, 7, 8)
ready
noprop call ctor
calc.call(cobj, 5, 7, 8)
ready
noprop apply
calc.apply(obj, [5, 7, 8])
ready
noprop apply ctor
calc.apply(cobj, [5, 7, 8])
ready

Revisions

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