Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.from vs Spread really
(version: 0)
Comparing performance of:
Array.from vs Spread
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
Array.from
var fooSet = new Set(); for(var i=0;i<10000;i++) { fooSet.add(i); } var other = Array.from(fooSet);
Spread
var fooSet = new Set(); for(var i=0;i<10000;i++) { fooSet.add(i); } var other = [...fooSet];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.from
Spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0
Browser/OS:
Firefox 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.from
2791.1 Ops/sec
Spread
2841.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The test compares two approaches for creating an array from a Set object: 1. `Array.from()` 2. The spread operator (`...`) **What is being tested?** In this case, we're testing how fast each approach can create an array of 10,000 integers by adding them to a Set object. **Options compared:** * `Array.from()` vs The spread operator (`...`) **Pros and Cons of each approach:** * **`Array.from()`:** + Pros: - More explicit and readable way to create an array from an iterable (in this case, a Set). - Allows for customization of the mapping function. + Cons: - May be slower due to the overhead of creating a new array and calling the `map()` method. * **The spread operator (`...`):** + Pros: - More concise and readable way to create an array from an iterable (in this case, a Set). - Often faster than `Array.from()`, as it avoids the overhead of creating a new array and calling `map()`. + Cons: - Less explicit and less customizable than `Array.from()`. - May not be compatible with older browsers or environments. **Library usage** Neither of these approaches relies on any external libraries. They are built-in features of JavaScript. **Special JS feature/syntax** There is no special JavaScript feature or syntax being used in this benchmark. It's purely a performance comparison between two common ways to create an array from a Set object. **Other alternatives** If you wanted to test alternative approaches, some options could be: * Using `Set.prototype.values()` and `Array.from()` * Using `Set.prototype.toArray()` (not supported in modern browsers) * Using a custom loop or recursive function to iterate over the Set * Using Web Workers for parallel execution Keep in mind that these alternatives may have different performance characteristics, readability issues, or compatibility problems.
Related benchmarks:
Splice vs Spread to insert at beginning of array
Javascript string to array mapping: Array.from() vs Spread syntax [...spread]
Array.from() vs spread []
new Array using spreading operator vs Array.slice()
spread vs ArrayFrom
Comments
Confirm delete:
Do you really want to delete benchmark?