Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
new Map vs set array to map
What is faster create new Map from two maps or set array items to map?
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
push array to map
108.8M/s
new Map
129K/s
View exact numbers
Test name
Executions per second
✓
push array to map
108,798,392 Ops/sec
new Map
128,743 Ops/sec
Script Preparation code:
var arr = []; for (let i = 1; i <= 100; i++) { arr.push({ id: i, name: `${i}` }); } var arr2 = []; for (let i = 101; i <= 200; i++) { arr.push({ id: i, name: `${i}` }); } var map = new Map(arr.map(item => [item.id, item]));
Tests:
new Map
const map2 = new Map(arr2.map(item => [item.id, item])); map = new Map([...map, ...arr2.map(item => [item.id, item])]);
push array to map
arr2.forEach(item => { map.set([item.id, item]) });