Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
concat two arrays: push vs destructuring
(version: 0)
Comparing performance of:
spread operator vs Push vs concatenation
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
spread operator
var params = [ "hello", true, 7 ] var other = [ ...params, ...["new", false, 3] ]
Push
var params = [ "hello", true, 7 ]; params.push(...["new", false, 3]);
concatenation
var params = [ "hello", true, 7 ]; var another = ["new", false, 3]; params.concat(another);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
spread operator
Push
concatenation
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0
Browser/OS:
Chrome 139 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
spread operator
25618308.0 Ops/sec
Push
37620744.0 Ops/sec
concatenation
9057613.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark compares the performance of three different approaches to concatenate arrays in JavaScript: using the spread operator (`...`), `push()` method with spread syntax, and the `concat()` method. **Approaches Compared** 1. **Spread Operator (`...`)**: This approach uses the spread operator to create a new array by copying elements from an existing array. 2. **Push with Spread Syntax**: This approach uses the `push()` method with the spread operator (`...`) to add new elements to an existing array. 3. **Concatenation using `concat()` Method**: This approach uses the `concat()` method to concatenate two arrays. **Pros and Cons of Each Approach** 1. **Spread Operator (`...`)**: * Pros: Efficient, concise, and modern syntax. * Cons: May not be supported in older browsers or environments. 2. **Push with Spread Syntax**: * Pros: Also efficient and concise, but may require more memory to create a new array. * Cons: May have performance overhead due to the creation of a new array. 3. **Concatenation using `concat()` Method**: * Pros: Well-supported in older browsers and environments. * Cons: Less efficient and less concise than other approaches. **Library and Special JS Features** None mentioned in the provided benchmark code. **Other Considerations** The benchmark is likely designed to: 1. Compare the performance of different approaches to concatenate arrays in JavaScript. 2. Provide insights into the efficiency and conciseness of various syntaxes. 3. Help developers make informed decisions about which approach to use depending on their specific needs and constraints. **Alternative Approaches** Other approaches to concatenate arrays might include: 1. Using `Array.prototype.reduce()` method. 2. Using `Array.prototype.push()`, followed by a loop or recursion to add elements. 3. Using `Array.prototype.forEach()` with the spread operator (`...`). 4. Using a library like Lodash, which provides utility functions for array manipulation. Note that the specific alternatives may vary depending on the context and requirements of the project.
Related benchmarks:
Array#concat vs Array#push
Array.prototype.concat vs spread operator vs push with spread
array spread operator vs concat vs push fix
Array concat vs spread operator vs push with long arrays
Array concat vs spread operator vs push with short arrays
Comments
Confirm delete:
Do you really want to delete benchmark?