Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
standard "for" vs "for...of"
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser:
Firefox 147
Operating system:
Windows
Device Platform:
Desktop
Date tested:
3 months ago
Test name
Executions per second
indexed for
314.2 Ops/sec
for...of
49.3 Ops/sec
Script Preparation code:
"use strict"; const LEN = 1 << 18; // 262,144 const REPS = 32; // Deterministic PRNG (LCG) let seed = 0x12345678 | 0; const nextInt = () => (seed = (Math.imul(seed, 1664525) + 1013904223) | 0); const data = new Int32Array(LEN); for (let i = 0; i < LEN; i++) data[i] = nextInt(); globalThis.__benchSink = 0; const DATA = data; const N = LEN; const R = REPS;
Tests:
indexed for
let sum = 0; for (let r = 0; r < R; r++) { for (let i = 0; i < N; i++) { const newVal = DATA[i]; sum += newVal; } } globalThis.__benchSink = sum;
for...of
let sum = 0; for (let r = 0; r < R; r++) { for (const v of DATA) { sum += v; } } globalThis.__benchSink = sum;