Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array concat x array spread
(version: 0)
Comparing performance of:
concat vs spread
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
concat
var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].concat(params);
spread
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
concat
spread
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/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
concat
17242998.0 Ops/sec
spread
58146512.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition:** The benchmark is testing two approaches to concatenate arrays in JavaScript: 1. Using the `concat()` method: ```javascript var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].concat(params); ``` 2. Using the spread operator (`...`): ```javascript var params = [ "hello", true, 7 ]; var other = [ 1, 2, ...params ]; ``` **Options being compared:** The benchmark is comparing two approaches: * `concat()`: The traditional way of concatenating arrays in JavaScript. * Spread operator (`...`): A newer syntax introduced in ECMAScript 2015 (ES6) that allows for more concise array concatenation. **Pros and Cons:** **Concat() Method:** Pros: * Wide support across browsers and older versions of JavaScript engines. * Well-established and widely used syntax. Cons: * Can be slower due to the need to create a new array and copy the elements from the original arrays. * May not perform as well on large datasets. **Spread Operator (`...`):** Pros: * Faster execution time, as it avoids creating a new array and copying elements. * More concise syntax, making it easier to read and write. Cons: * Requires support for ES6 and later versions of JavaScript engines. Older browsers may not execute this code correctly or at all. * May have issues with certain browser implementations or extensions. **Library usage:** None of the benchmark cases use any external libraries. The focus is solely on testing the two different array concatenation approaches in vanilla JavaScript. **Special JS features or syntax:** The spread operator (`...`) is a relatively new feature introduced in ES6, so it's worth noting that not all browsers support it natively. However, most modern browsers, including Chrome, do support this feature. **Other alternatives:** There are other approaches to concatenate arrays in JavaScript, such as using `Array.prototype.push()` or `Array.prototype.splice()`. However, these methods are not tested in this benchmark case. It's worth noting that the benchmark results show that the spread operator (`...`) is slightly faster than the traditional `concat()` method in this specific test case. This may vary depending on the specific use case and JavaScript engine implementation.
Related benchmarks:
spread vs concat vs unshift
simple spread vs concat benchmark
Splice+Spread vs concat to concat arrays
Array merge (spread, concat)
spread vs concat vs unshift vs aaa
Comments
Confirm delete:
Do you really want to delete benchmark?