Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
indexed 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++) { sum += DATA[i]; } } 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser/OS:
Chrome 144 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
indexed for
90.0 Ops/sec
for...of
19.1 Ops/sec
Related benchmarks:
Array.reduce vs for loop vs Array.forEach vs for of loop - 30
Array.reduce vs for loop vs Array.forEach vs decrement while 2
Array.reduce vs for loop vs Array.forEach vs decrement while 3
array vs set index deletion
find half some
SortingTests
1312312
Binary search in sorted 100k int array
Unique Instance Test
Comments
Confirm delete:
Do you really want to delete benchmark?