Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.from vs Spread123
(version: 0)
Comparing performance of:
Array.from vs Spread
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
Array.from
var fooSet = []; for(var i=0;i<10000;i++) { fooSet.push(i); } var other = Array.from(fooSet);
Spread
var fooSet = []; for(var i=0;i<10000;i++) { fooSet.push(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:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.from
38380.7 Ops/sec
Spread
38894.5 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 Definition** The benchmark is defined by two test cases: `Array.from` and `Spread`. The purpose of this benchmark is to compare the performance of two ways to create an array from another iterable (in this case, a set). **Options Compared** Two options are compared: 1. **`Array.from()`**: This method creates a new array instance by copying elements from another iterable (such as an array or a set) and returns it. 2. **Spread Operator (`...`)**: This operator creates a new array instance by spreading the elements of another iterable (such as an array or a set). **Pros and Cons** * **`Array.from()`**: + Pros: It's a more explicit and type-safe way to create an array from another iterable. It also allows for specifying an initial length for the resulting array. + Cons: It can be slower than the spread operator, especially when dealing with large datasets. * **Spread Operator (`...`)**: + Pros: It's faster and more concise than `Array.from()`. It's also widely used in modern JavaScript codebases. + Cons: It can lead to less explicit and less type-safe code, which might be problematic for some developers. **Library Usage** Neither of the options uses a library. However, it's worth noting that both methods are part of the ECMAScript standard and are supported by most JavaScript engines out-of-the-box. **Special JS Feature or Syntax** The benchmark doesn't use any special JavaScript features or syntax. It's written in plain vanilla JavaScript and should be easily recognizable to developers familiar with the language. **Other Alternatives** Other ways to create an array from another iterable include: * `Array.prototype.slice()` or `Array.prototype.splice()`: These methods can be used to extract a subset of elements from another array, but they're not as efficient as `Array.from()` and the spread operator for creating an entirely new array. * `Array.prototype.map()` or `Array.prototype.forEach()`: These methods can be used to transform or iterate over another iterable, but they're not designed specifically for creating arrays. It's worth noting that in modern JavaScript, you'd typically use `Array.from()` instead of the spread operator when working with iterables. The spread operator is more commonly used when working directly with arrays or other array-like objects.
Related benchmarks:
Javascript string to array mapping: Array.from() vs Spread syntax [...spread]
Push vs LHS 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?