Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map copying
(version: 1)
Comparing performance of:
From map vs From array vs Step-by-step
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const array = Array.from({length: 10_000}, () => Math.floor(Math.random() * 10_000_000)); const map = new Map(); array.forEach((x, i) => map.set(x, i));
Tests:
From map
return new Map(map);
From array
return new Map([...map])
Step-by-step
const newMap = new Map(); map.keys().forEach(x => newMap.set(x, map.get(x))); return newMap
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
From map
From array
Step-by-step
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Browser/OS:
Chrome 118 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
From map
1514.0 Ops/sec
From array
1113.0 Ops/sec
Step-by-step
1241.9 Ops/sec
Related benchmarks:
.map vs .forEach
set + array.from + map vs map + set
Performance of JavaScript .forEach, for in
Performance of JavaScript .forEach, for in v3
ak;ldjf;lakdjf
Iterator to Array Benchmark
Map. foreach
Map iteration + clearing
Map.values().toArray() vs Array.from(Map.values()) vs [...Map.values()]
Comments
Confirm delete:
Do you really want to delete benchmark?