Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator vs push w/o jQuery
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method and push
Comparing performance of:
Array.prototype.concat vs spread operator vs Push
Created:
7 years ago
by:
Registered User
Jump to the latest result
Tests:
Array.prototype.concat
var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].concat(params);
spread operator
var params = [ "hello", true, 7 ] var other = [ 1, 2, ...params ]
Push
var params = [ "hello", true, 7 ]; params.push(1); params.push(2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array.prototype.concat
spread operator
Push
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided JSON represents a JavaScript benchmark test case on MeasureThat.net, which compares the performance of three approaches for concatenating arrays: 1. `Array.prototype.concat()` 2. The new ES6 spread operator (`...` syntax) 3. Using the `push()` method without assigning to a new array **Options Compared** The benchmark tests the execution speed of each approach on the same input data, which consists of an initial array `[ "hello", true, 7 ]` and another array `[ 1, 2 ]`. The test cases are: * `Array.prototype.concat()`: Concatenates the two arrays using the `concat()` method. * Spread operator (`...` syntax): Spreads the elements of the initial array into a new array. * Push: Pushes each element of the initial array onto the target array `[ 1, 2 ]`. **Pros and Cons of Each Approach** * **Array.prototype.concat()**: This is a widely supported method in JavaScript. It has a time complexity of O(n), where n is the length of the arrays being concatenated. However, it can be slow for large arrays because it creates a new array. * Spread operator (`...` syntax): This approach was introduced in ES6 and has become popular due to its concise syntax. It has a time complexity of O(k), where k is the number of elements spread into the new array. However, it may not be supported in older browsers or versions of JavaScript. * Push: Using `push()` without assigning to a new array can be slow because it involves mutating the existing array and checking for bounds on each push operation. **Library and Special JS Features** There is no specific library used in this benchmark. However, note that the spread operator (`...` syntax) relies on the ECMAScript 2015 standard (ES6), which may not be supported in all browsers or versions of JavaScript. **Other Considerations** * The performance differences between these approaches may vary depending on the specific use case and environment. * Other factors like memory allocation, garbage collection, and CPU usage can also impact performance in a benchmarking test. * MeasureThat.net's benchmarking framework aims to provide a fair comparison by using the same input data and execution environment for each test case. **Alternatives** Other alternatives for concatenating arrays could include: * Using `Array.prototype.reduce()` or other reduction methods * Creating a new array using `Array.from()` * Using a library like Lodash's `concat` function However, these approaches may have different trade-offs in terms of performance, readability, and compatibility with older browsers or versions of JavaScript.
Related benchmarks:
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator (add)
Array.prototype.concat vs spread operator (fix)
Array.prototype.concat vs spread operator on large array
Array.prototype.concat vs spread operator on small array
Comments
Confirm delete:
Do you really want to delete benchmark?