Array from vs spread

Benchmark created on


Setup

let set = new Set();
let objMap = {};
let map = new Map();
for (let i = 0; i < 1000; i++) {
  	const rnd = Math.round(Math.random()*1000);
  	objMap[`item${i}`] = rnd;
    map.set(`item${i}`, rnd);
    set.add(rnd);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Spread from map.values
let arr = [...map.values()];
ready
Spread from object.values
let arr = [...Object.values(objMap)];
ready
Array.from(map.values)
let arr = Array.from(map.values());
ready
Array.from(object. values)
let arr = Array.from(Object.values(objMap));
ready
Spread from set
let arr = [...set];
ready
Array from Set
let arr = Array.from(set);
ready

Revisions

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