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 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 121
Operating system:
Android
Device Platform:
Mobile
Date tested:
2 years ago
Test name
Executions per second
conditional
2746096.5 Ops/sec
no_Op
185691.8 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); }