Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
MinMax test
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Browser:
Firefox 124
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
for
3751836.8 Ops/sec
foreach
2980187.8 Ops/sec
forin
368777.7 Ops/sec
forof
1080989.8 Ops/sec
Script Preparation code:
var arrays = []; var range = {min:0,max:0}; for (let i = 0; i < 100; i++) { arrays.push({ name: 'asdf', price: Math.random() * (10000 - 1000) + 1000 }) }
Tests:
for
for (let i = 0; i < 100; i++) { const price = arrays[i].price; if (price < range.min) range.min = price; else if (price > range.max) range.max = price; }
foreach
arrays.forEach((obj)=>{ const price = obj.price; if (price < range.min) range.min = price; else if (price > range.max) range.max = price; })
forin
for (const i in arrays){ const price = arrays[i].price; if (price < range.min) range.min = price; else if (price > range.max) range.max = price; }
forof
for (const obj of arrays){ const price = obj.price; if (price < range.min) range.min = price; else if (price > range.max) range.max = price; }