Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Convert Set to Array
(version: 0)
Comparing performance of:
Array.from() vs spread operator vs for...of loop vs iterator.next()
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var testSet = new Set(); for (let i = 1; i <= 100000; i++) { testSet.add(i); }
Tests:
Array.from()
const arrayFrom = Array.from(testSet.values());
spread operator
const arraySpread = [...testSet];
for...of loop
const arrayForOf = []; for (const value of testSet) { arrayForOf.push(value); }
iterator.next()
const arrayWhileNext = []; let iterator = testSet.values(); let next = iterator.next(); while (!next.done) { arrayWhileNext.push(next.value); next = iterator.next(); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Array.from()
spread operator
for...of loop
iterator.next()
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/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.from()
2653.9 Ops/sec
spread operator
3057.9 Ops/sec
for...of loop
927.2 Ops/sec
iterator.next()
958.0 Ops/sec
Related benchmarks:
For i / For of / ForEach
js array perfomance
set to array performance (slice, Array.from, forEach)
TestArrayAllocationv2
DDS Array vs Set - performance v4
for-of-foreach-1
Array.from() vs Spread with 10K elements
Comments
Confirm delete:
Do you really want to delete benchmark?