Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
spread vs iterator for getting first element (fixed)
(version: 1)
fixed elements array creation
Comparing performance of:
spread vs iterator vs destructuring vs iterator helpers
Created:
9 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const elements = new Set(Array.from({length:10000},(_, i) => i));
Tests:
spread
const v = [...elements][0];
iterator
function first(iter){ for(const v of iter) return v; return undefined; } const v = first(elements);
destructuring
const [v] = [...elements];
iterator helpers
const [v] = elements.values().take(1).toArray()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
spread
iterator
destructuring
iterator helpers
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0
Browser/OS:
Firefox 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
spread
13492.6 Ops/sec
iterator
34750600.0 Ops/sec
destructuring
13083.1 Ops/sec
iterator helpers
5745813.5 Ops/sec
Related benchmarks:
Iterators
Spread performance
Array.from vs spread vs construct manually
Array.from vs spread vs construct manually 2
Array.from vs spread vs construct manually 5
Array.from vs spread 123
Iterator with Array#pop() vs iterator with Array#shift()
Array.from vs Spread2
spread vs iterator for getting first element
Comments
Confirm delete:
Do you really want to delete benchmark?