Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
if len-1 vs direct for-each
if len-1 vs direct for-each
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser:
Chrome 127
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
if then-1
13096241.0 Ops/sec
directly for-each
16440073.0 Ops/sec
directly for-of
18798458.0 Ops/sec
directly for
12858363.0 Ops/sec
for-each 2
17293394.0 Ops/sec
Script Preparation code:
var xs = [1]; function f(x) { return x; }
Tests:
if then-1
if (xs.length === 1) { f(xs[0]); } else { xs.forEach(f); }
directly for-each
xs.forEach(f);
directly for-of
for (const x of xs) { f(x); }
directly for
for (let i = 0, n = xs.length; i < n; ++i) { f(xs[i]); }
for-each 2
xs.forEach(x => { f(x); });