Array.from vs Spread (v5)

Revision 5 of this benchmark created on


Setup

window.mySet = new Set();
window.myArr = [];
for (let i = 0; i < 1000000; i++) {
	window.mySet.add(i);
	window.myArr.push(i);
}
window.results = []

Teardown

window.results.length = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Array.from (on Set)
const data = Array.from(window.mySet);
window.results.push(data[(Math.random()*data.length) >> 0])
ready
Spread (on Set)
const data = [...window.mySet];
window.results.push(data[(Math.random()*data.length) >> 0])
ready
lmao (on Set)
const data= Array.from([...window.mySet]);
window.results.push(data[(Math.random()*data.length) >> 0])
ready
Array.from (on Array)
const data = Array.from(window.myArr);
window.results.push(data[(Math.random()*data.length) >> 0])
ready
Spread (on Array)
const data = [...window.myArr];
window.results.push(data[(Math.random()*data.length) >> 0]);
ready

Revisions

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