Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.from vs Spread using 1000000 elements
(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 = new Set(); for(var i=0;i<1000000;i++) { fooSet.add(i); } var other = Array.from(fooSet);
Spread
var fooSet = new Set(); for(var i=0;i<1000000;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:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.from
28.2 Ops/sec
Spread
28.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark and explain what's being tested. **What is being tested?** The provided JSON represents two test cases: `Array.from` and `Spread`. Both tests measure the performance of converting a set of 1,000,000 elements to an array using different approaches. **Options compared:** * **Array.from**: Uses the `Array.from()` method to create an array from a given iterable (in this case, a `Set`). * **Spread**: Uses the spread operator (`...`) to convert a set to an array. **Pros and Cons of each approach:** * **Array.from**: + Pros: - More explicit and readable syntax. - Can be faster for large datasets since it doesn't involve creating an intermediate array. + Cons: - May have additional overhead due to the function call and iterator creation. * **Spread**: + Pros: - Often considered more concise and readable syntax. - Can be faster since it avoids the overhead of function calls and iterator creation. + Cons: - Less explicit and may be harder to understand for those unfamiliar with spread operators. **Library used:** * **Set**: A built-in JavaScript object that allows you to store unique values. In this test, a `Set` is created and populated with 1,000,000 elements using the `add()` method. * **Array.from() and Spread operator**: These are part of the ECMAScript standard and do not rely on any external libraries. **Special JS feature or syntax:** * The use of the spread operator (`...`) in the `Spread` test case is a modern JavaScript feature introduced in ECMAScript 2018 (ES2018). It allows you to convert an iterable to an array by spreading its elements. **Other considerations:** * Both tests measure the time it takes to execute the conversion, which can be influenced by various factors such as the machine's CPU, memory, and JavaScript engine optimization. * The test results may not be representative of all scenarios or use cases, as the benchmarking environment and system specifics can affect performance. **Other alternatives:** * For converting sets to arrays, other approaches could include using `Array.prototype.push()` or `Array.prototype.concat()`, but these would likely have similar overhead compared to `Array.from()` and spread. * Alternative ways to create a set of 1,000,000 elements might include using an array and adding each element individually, but this approach would be less memory-efficient. In summary, the benchmark measures the performance difference between two approaches for converting sets to arrays: `Array.from()` and the spread operator. The test results provide insight into which approach is faster in a specific JavaScript engine version and environment.
Related benchmarks:
Push vs LHS spread
Spread vs Slice operators in JS
Array.prototype.slice vs spread operator - large array 100000
Array.from vs Spread using 1000000 elements / only counts conversion
Array.from vs Spread using 10000 elements / only counts conversion
Comments
Confirm delete:
Do you really want to delete benchmark?