Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Explicit call vs apply
See if there is a real benefit to handle small arity function calls with explicit calls or if apply is sufficient.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0
Browser:
Firefox 150
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one month ago
Test name
Executions per second
Explicit call
124464208.0 Ops/sec
Apply call
15801184.0 Ops/sec
Apply with arguments call
2614423.0 Ops/sec
Script Preparation code:
function wrapExplicit(fn) { return function(a1, a2, a3) { return fn.call(this, this, a1, a2, a3) } } function wrapApply(fn) { return function() { var args = [this] for (let i = 0, len = arguments.length; i < len; i++) { args[i + 1] = arguments[i] } return fn.apply(this, args) } } function wrapApplyWithArguments(fn) { return function() { return fn.apply(this, [this].concat(arguments)) } } function fn(thisArg, a1, a2, a3) { thisArg.result = a1 + a2 + a3 } var explicitCall = { fn: wrapExplicit(fn) } var applyCall = { fn: wrapApply(fn) } var applyWithArgumentsCall = { fn: wrapApplyWithArguments(fn) }
Tests:
Explicit call
explicitCall.fn(Math.random(), Math.random(), Math.random())
Apply call
applyCall.fn(Math.random(), Math.random(), Math.random())
Apply with arguments call
applyWithArgumentsCall.fn(Math.random(), Math.random(), Math.random())