Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Set vs Filter vs forEach vs forLoop vs filterWithSet vs map for unique
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Android 13; Mobile; rv:122.0) Gecko/122.0 Firefox/122.0
Browser:
Firefox Mobile 122
Operating system:
Android
Device Platform:
Mobile
Date tested:
2 years ago
Basic forEach
3.7M/s
Filter
326K/s
filterWithSet
252K/s
for loop
249K/s
Array from set
219K/s
Set spread
205K/s
View exact numbers
Test name
Executions per second
✓
Basic forEach
3,712,156 Ops/sec
Filter
325,722 Ops/sec
filterWithSet
251,854 Ops/sec
for loop
249,373 Ops/sec
Array from set
218,621 Ops/sec
Set spread
204,908 Ops/sec
Script Preparation code:
var array = Array.from({length: 40}, () => Math.floor(Math.random() * 140));
Tests:
Set spread
const f = [... new Set(array)]
Array from set
const s = new Set(array) const l = Array.from(s)
Filter
const b = array.filter((i,index) => array.indexOf(i)=== index)
Basic forEach
const set = {} array.forEach(val => set.hasOwnProperty(val) ? set[val] = true : '') const b = Object.keys(set)
for loop
const set = {} for(var i = 0, l = array.length; i < l; i++){ if(!set.hasOwnProperty(array[i])) set[array[i]] = true } const b = Object.keys(set)
filterWithSet
const set = {} const b = array.filter((val) => { if(!set.hasOwnProperty(val)) { set[val] = true return true } return false })