Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
standard "for" vs "for...of"
(version: 1)
Comparing performance of:
indexed for vs for...of
Created:
3 months ago
by:
Guest
Jump to the latest result
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;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
indexed for
for...of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
indexed for
314.2 Ops/sec
for...of
49.3 Ops/sec
Related benchmarks:
Powers of two
Powers of two
Powers of two
Powers of two
Powers of two
Powers of two
IndexOf_vs_includes
includes_vs_IndexOf
indexed for vs for...of
Comments
Confirm delete:
Do you really want to delete benchmark?