Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator (b)
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
2 years ago
by:
Guest
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 ]
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:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.prototype.concat
8846934.0 Ops/sec
spread operator
36172300.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested, compared, and the pros and cons of different approaches. **Benchmark Overview** The MeasureThat.net benchmark is designed to compare two approaches for concatenating arrays in JavaScript: the traditional `Array.prototype.concat()` method and the new ES6 spread operator (`...`). **Test Cases** There are two test cases: 1. **Array.prototype.concat**: This test case creates an array `params` with string values, a boolean value, and an integer value. It then concatenates this array to another array `[1, 2]` using the traditional `concat()` method. 2. **Spread Operator**: This test case is similar to the first one, but instead of using `concat()`, it uses the spread operator (`...`) to concatenate the two arrays. **Options Compared** The benchmark compares the performance of: * Traditional `Array.prototype.concat()` method * New ES6 spread operator (`...`) **Pros and Cons of Different Approaches:** * **Traditional `Array.prototype.concat()` method**: + Pros: widely supported, well-documented, and easy to understand. + Cons: can be slower due to the overhead of creating a new array and iterating over the original arrays. * **New ES6 spread operator (`...`)**: + Pros: faster, more concise, and expressive. It also avoids the need for explicit array creation and iteration. + Cons: not as widely supported (older browsers may not support it), and its behavior can be unexpected if not used correctly. **Library Usage** None of the test cases uses any external libraries or frameworks. **Special JS Feature/Syntax** The benchmark leverages the new ES6 spread operator (`...`) feature, which was introduced in ECMAScript 2015. This syntax allows for spreading array elements into a new array, making it easier to concatenate arrays and create new arrays with a subset of existing values. **Other Alternatives** Other alternatives for concatenating arrays could include: * Using `Array.prototype.push()` or `Array.prototype.splice()` methods * Utilizing libraries like Lodash or Ramda, which provide more functional programming constructs for array manipulation * Using other spread operator variants (e.g., `Array.prototype.unshift()`, `Array.prototype.splice()`) Keep in mind that the choice of approach depends on the specific use case and performance requirements. **Benchmark Preparation Code** The provided script preparation code is empty, indicating that MeasureThat.net will generate this code automatically for each test case.
Related benchmarks:
Array.prototype.concat vs Spread operator
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator real
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?