Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.from() versus checking to see if item is already an array
(version: 1)
Comparing performance of:
No check to see if there is an array vs Check to see if there is an array
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Tests:
No check to see if there is an array
const [Builder, add] = (Math.random() > 0.5) ? [Array, 'push'] : [Set, 'add']; const collection = new Builder(); for (let i = 0; i < 1000; i++) { collection[add](i); } const result = Array.from(collection);
Check to see if there is an array
const [Builder, add] = (Math.random() > 0.5) ? [Array, 'push'] : [Set, 'add']; const collection = new Builder(); for (let i = 0; i < 1000; i++) { collection[add](i); } const result = Array.isArray(collection) ? collection : Array.from(collection);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
No check to see if there is an array
Check to see if there is an array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
No check to see if there is an array
58275.6 Ops/sec
Check to see if there is an array
58432.4 Ops/sec
Related benchmarks:
Unique values (large list)
Set.has vs Array.includes Large Collections
set + array.from + map vs map + set
forEach vs Some vs for (correction)
javascript loops small
Pushing vs Filling
Duplicate to unique array time complexity measure w/ different approaches.
javascript loops with reduce 4
javascript loops with reduce 5
Comments
Confirm delete:
Do you really want to delete benchmark?