Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
filter -> includes vs filter -> Set.has() vs populate Map v2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
filter -> includes
65671.7 Ops/sec
filter -> Set.has()
18387.1 Ops/sec
Populate Map
14809603.0 Ops/sec
Script Preparation code:
var books = Array.from({length: 1000}, (_, index) => ({id: index, mensionedIn: [{ids: [index, index + 1, index + 2, index + 3]}]})) var bookMap = new Map(); books.forEach(book => { book.mensionedIn.forEach(mension => { mension.ids.forEach(id => { if (!bookMap.has(id)) { bookMap.set(id, []); } bookMap.get(id).push(book); }); }); });
Tests:
filter -> includes
var getBooksWithIndex_1 = (index) => { return books.filter(book => book.mensionedIn.some(mensioned => mensioned.ids.includes(index))) } getBooksWithIndex_1(4) getBooksWithIndex_1(5)
filter -> Set.has()
const getBooksWithIndex_2 = (index) => { const bookIdSet = new Set([index]) return books.filter(book => book.mensionedIn.some(mensioned => mensioned.ids.some(bookIndex => bookIdSet.has(bookIndex)))) } getBooksWithIndex_2(4) getBooksWithIndex_2(5)
Populate Map
const getBooksWithIndex_3 = (index)=> { return bookMap.get(index); } getBooksWithIndex_3(4) getBooksWithIndex_3(5)