Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
noop vs conditional execution
Is it faster to run a noop (no-op, no op) function in javascript or is it faster to check if a function exist before calling it? let's find out!
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Browser:
Safari 18
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
11 months ago
Test name
Executions per second
conditional
498576416.0 Ops/sec
no_Op
61446404.0 Ops/sec
Script Preparation code:
var no_Op = function() {}; var checkMe = [ void 0, function(x, y) { x.n += y; }, function(x, y) { x.n += y; }, void 0, function(x,y) { x.n += y; }, void 0, function(x, y) { x.n += y; }, void 0 ]; var runMe = checkMe.map(fn => fn || no_Op);
Tests:
conditional
const accumulator = {n: 0}; for (let i = 0, fn; i < checkMe.lenght; i++) { fn = checkMe[i]; if (fn) { fn(accumulator, i); } }
no_Op
const accumulator = {n: 0}; for (let i = 0; i < runMe.length; i++) { runMe[i](accumulator, i); }