AAaq

Benchmark created on


Setup

const users = new Array(1000).fill(true).map((v,i) => {
	return {
		id: `${i}`, 
		value: Math.random()
	}
}); 

const dataToMap =  new Array(100).fill(true).map((v,i) => `${i}`); 

Test runner

Ready to run.

Testing in
TestOps/sec
Nested loop
const value = dataToMap
    .map((data) => users.find((user) => user.id === data))
    .filter((user) => user !== undefined);
    
ready
Map
const map = new Map(); 
users.forEach(v => {
	map.set(v.id, v)
}); 

const value = dataToMap.map((v) => {
	return map.get(v)
}).filter(v => v!==undefined); 


ready
object
const map = {}
users.forEach(v => {
	map[v.id] =v; 
}); 

const value = dataToMap.map((v) => {
	return map[v];
}).filter(v => v!==undefined); 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.