Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Simple array spread vs array push
(version: 0)
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
var params = [ "hello", true, 7 ]; params = [...params, 1]
spread operator
var params = [ "hello", true, 7 ] params.push(1);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.prototype.concat
spread operator
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.prototype.concat
36898492.0 Ops/sec
spread operator
257935840.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON for MeasureThat.net and explain what's being tested. **Benchmark Definition** The benchmark definition is null, which means that the test doesn't specify any specific algorithm or operation to be compared. Instead, it seems to be comparing two different approaches: 1. **Array spread operator**: The first approach uses the array spread operator (`[...params, 1]`) to create a new array by spreading the original array `params` and then appending the value `1`. This is equivalent to using the `concat()` method. 2. **Array push**: The second approach uses the `push()` method to add the value `1` to the end of the original array `params`. **Options Compared** The two options being compared are: * Using the array spread operator (`[...params, 1]`) * Using the `push()` method with an array literal (`params.push(1)`) **Pros and Cons** **Array Spread Operator:** Pros: * More concise and expressive * Can be faster for large arrays since it avoids the overhead of creating a new array object Cons: * Less readable for some developers who are not familiar with this syntax * May not work as expected in older browsers or environments that don't support this feature **Array Push:** Pros: * More widely supported and understood by developers * Easier to read and maintain, especially for those who prefer a more traditional approach Cons: * Can be slower since it involves creating a new array object, which can lead to additional memory allocations. **Library Considerations** None of the libraries are explicitly mentioned in this benchmark. However, if we consider the context, the `concat()` method is typically implemented using the `push()` method internally, so there's no significant difference in terms of performance or functionality. **Special JS Features or Syntax** The array spread operator (`[...params, 1]`) and the `push()` method with an array literal (`params.push(1)`) are both syntax features introduced in ECMAScript 2015 (ES6). These features provide a more concise way to create arrays and add elements, but may not work as expected in older browsers or environments. **Other Alternatives** If you wanted to compare these approaches using different methods, here are some alternatives: * Using the `Array.prototype.slice()` method with the spread operator (`[...params.slice(), 1]`) * Using a custom implementation of the array push operation * Comparing the performance of other array manipulation techniques, such as `setInterval()`, `requestAnimationFrame()`, or WebAssembly-based solutions. Keep in mind that each alternative would require significant changes to the benchmark definition and test cases.
Related benchmarks:
Pushing items via Array.push vs. Spread Operator
Javascript: Spread vs push
JS array spread operator vs push
Array .push() vs spread operator
Spread vs Push when adding into array
Comments
Confirm delete:
Do you really want to delete benchmark?