Array looping entries
Finding out the performance hit of array entries
Date tested:
one month ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0
Test name
Executions per second
for of loop
72421.4 Ops/sec
Simple for loop (reverse)
32071.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var arr = []; for( var cpt = 0; cpt < 1000; cpt++ ) { arr.push( Math.random() ); }
Tests:
for of loop
const arr2 = [] for (const entry of arr) { arr2.push(entry) }
Simple for loop (reverse)
const arr2 = [] for (const [i, entry] of arr.entries()) { arr2.push(entry) }
Open this result on MeasureThat.net