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 (X11; Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0
Browser:
Firefox 135
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
push array to map
1722.8M/s
new Map
86K/s
View exact numbers
Test name
Executions per second
✓
push array to map
1,722,795,136 Ops/sec
new Map
85,952 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]) });