Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.from vs Spread #2
(version: 0)
Comparing performance of:
Array.from vs Spread
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var fooSet = new Set(); for(var i=0;i<100;i++) { fooSet.add(i); }
Tests:
Array.from
var other = Array.from(fooSet);
Spread
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:
8 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0
Browser/OS:
Firefox 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.from
351207.2 Ops/sec
Spread
353498.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **What is being tested?** The provided JSON represents a benchmark test comparing two approaches: `Array.from()` and the spread operator (`...`). **Options compared** There are two options being compared: 1. **`Array.from(fooSet)`**: This method creates a new Array from an iterable (in this case, a Set object) by iterating over its elements. 2. **`[...fooSet]`**: This syntax uses the spread operator to create a new Array from an iterable. **Pros and Cons** **`Array.from()`**: Pros: * More explicit and readable way to create arrays from iterables * Allows for customization through options (e.g., `Array.from(iterable, callback)`) Cons: * May incur additional overhead due to the creation of a new array **Spread Operator (`[...fooSet]`)** Pros: * Concise and expressive syntax * Fast and efficient way to create arrays from iterables Cons: * Less explicit and potentially less readable than `Array.from()` * Limited customization options **Other considerations** In this benchmark, the Set object is used as an iterable source. This choice may be specific to the test case and not representative of all use cases. **Library usage (if applicable)** The `Set` object is a built-in JavaScript library that provides a data structure for storing unique values. In this case, it's used to create an iterable source for both comparison methods. **Special JS feature or syntax** There are no special features or syntaxes mentioned in the benchmark definition or test cases. **Alternative approaches** Other alternatives to compare `Array.from()` and the spread operator could include: * Using a custom iterator or generator function * Comparing with other array creation methods, such as `Array.prototype.concat()` * Evaluating performance differences for specific use cases (e.g., large datasets) Keep in mind that the benchmark's focus is on comparing two specific approaches, making it challenging to add alternative approaches without altering the test case's intent.
Related benchmarks:
JavaScript spread operator vs Object.assign performance immutable
JavaScript spread operator vs Object.assign (no mutate) performance
JavaScript spread operator vs Object.assign performance with overwite
JavaScript spread operator vs Object.assign performance v3455676854743
Array.from vs Spread using 10000 elements
Comments
Confirm delete:
Do you really want to delete benchmark?