Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
concat vs push vs spread
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method and push
Comparing performance of:
Concat vs Spread operator vs Push
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Concat
var a = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); var b = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); var c = a.concat(b);
Spread operator
var a = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); var b = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); var c = [ ...a, ...b ]
Push
var a = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); var b = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); var c = a.push(...b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
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):
**Benchmark Overview** The provided JSON represents a benchmark test created on MeasureThat.net, which compares the performance of three different methods for concatenating arrays: `concat()`, `push()` with the spread operator (`...`), and the ES6 spread operator itself. **Methods Comparison** 1. **Concat()**: The traditional method of concatenating two arrays using the `concat()` function. 2. **Push() with Spread Operator**: This method uses the spread operator (`...`) to push elements from one array into another. It's a more concise way of achieving the same result as `concat()`. 3. **ES6 Spread Operator**: This method directly uses the spread operator (`...`) to concatenate two arrays. **Pros and Cons** * **Concat()**: + Pros: Simple, widely supported, and well-documented. + Cons: Can be slower due to the overhead of creating a new array. * **Push() with Spread Operator**: + Pros: More concise, might be faster than `concat()` since it avoids creating a new array. + Cons: Less intuitive for those not familiar with spread operators, and its performance benefits are only noticeable in specific scenarios. * **ES6 Spread Operator**: + Pros: Most concise and expressive way of concatenating arrays, good performance characteristics. + Cons: Requires support for ES6 syntax, might be unfamiliar to older browsers or developers. **Library Use** None of the provided benchmark tests use any external libraries. **Special JS Features/Syntax** * **Spread Operator (`...`)**: Introduced in ECMAScript 2015 (ES6), it allows for spreading elements from an array into another array. The `push()` method is used with the spread operator to concatenate arrays. * **`concat()` function**: A built-in JavaScript function that concatenates two or more arrays. **Benchmark Results** The latest benchmark results show: * `Push()` with Spread Operator: 1145.309326171875 executions per second * ES6 Spread Operator: 1091.0667724609375 executions per second * Concat(): 1164.4434814453125 executions per second **Other Alternatives** For those interested in exploring other alternatives, you can also consider: * Using `Array.prototype.reduce()` to concatenate arrays. * Utilizing the `Array.prototype.splice()` method for array concatenation. However, these alternatives are less commonly used and might not offer significant performance benefits over the original three methods being compared.
Related benchmarks:
concat 2 arrays: Array.prototype.concat vs spread operator
Array concat vs spread operator vs push #3
spread operator vs push Brian
spread operator vs push Brian2
Array concat vs spread operator vs push larger list
Comments
Confirm delete:
Do you really want to delete benchmark?