Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
map vs reverse for vs for vs push vs unshift
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 17
Operating system:
iOS 17.5.1
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
map
33819.2 Ops/sec
reverse for
22108.6 Ops/sec
for
16290.6 Ops/sec
for push
15979.5 Ops/sec
reverse for unshift
13705.7 Ops/sec
Script Preparation code:
var arr = new Array(500).fill().map(()=>({id:Math.random()**Math.random()**Math.random()}));
Tests:
map
const res1=arr.map(({id})=>id>Math.random()?{foo:'bar'}:{bar:'foo'});
reverse for
const res2=new Array(arr.length); for (let i=arr.length-1;i>-1;i--){ res2[i]=arr[i].id>Math.random()?{foo:'bar'}:{bar:'foo'} }
for
const res2=new Array(arr.length); for (let i=0;i<arr.length;i++){ res2[i]=arr[i].id>Math.random()?{foo:'bar'}:{bar:'foo'} }
for push
const res2=[] for (let i=0;i<arr.length;i++){ res2.push(arr[i].id>Math.random()?{foo:'bar'}:{bar:'foo'}) }
reverse for unshift
const res2=new Array(); for (let i=arr.length-1;i>-1;i--){ res2.unshift(arr[i].id>Math.random()?{foo:'bar'}:{bar:'foo'}) }