Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
javascript concat vs spread operator vs push2
(version: 0)
javascript concat vs spread operator vs push
Comparing performance of:
concat vs spread operator vs push
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
concat
var existed = Array.from({length:100},(_,i)=>i) var params = Array.from({length:100},(_,i)=>i) var other = existed.concat(params);
spread operator
var existed = Array.from({length:100},(_,i)=>i) var params = Array.from({length:100},(_,i)=>i) var other = [ ...existed, ...params ];
push
var existed = Array.from({length:100},(_,i)=>i) var params = Array.from({length:100},(_,i)=>i) var other = existed.push(...params);
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):
Let's break down the benchmark and explain what's being tested. **What is being tested?** The benchmark measures the performance of three different ways to concatenate arrays in JavaScript: 1. `concat()`: Using the `concat()` method to combine two arrays. 2. Spread operator (`...`): Using the spread operator to combine two arrays. 3. `push(...)` : Using the `push()` method with an array of arguments (`...params`) to add elements to an existing array. **Options compared:** Each test case compares the performance of one specific approach (concat, spread operator, or push) versus another. For example: * The "concat" test case measures the performance of `existed.concat(params)` against two other approaches. * The "spread operator" test case measures the performance of `[...existed, ...params]` against two other approaches. **Pros and cons of each approach:** 1. **concat()**: This method is widely supported and understood in JavaScript. However, it can be slower than the spread operator or push methods because it creates a new array object. 2. **Spread operator (`...`)**: The spread operator is a modern feature that has become increasingly popular in recent years. It's often faster than `concat()` but may not work in older browsers. 3. **push(...)** : This method is also known as "rest parameter" and was introduced in ECMAScript 2015 (ES6). It can be slower than the spread operator because it needs to parse and execute a function call. **Library:** There is no explicit library mentioned in the benchmark definition or individual test cases. However, some libraries like Lodash may provide implementations of these methods that could affect performance. **Special JS feature/syntax:** The benchmark uses modern JavaScript features such as: * Arrow functions (`=>`) * Destructuring assignment ( `_i` in `Array.from({length:100},(_,i)=>i)` ) * Rest parameters ( `...params` in `[...existed, ...params]` ) These features are not included in older browsers that don't support ES6+, so the benchmark only provides results for modern browsers. **Other alternatives:** Other ways to concatenate arrays in JavaScript include: * Loops (e.g., using `for` loops) * Array methods like `slice()` and `splice()` * Libraries like Lodash, which provide various array utilities However, these approaches are not being tested in this benchmark.
Related benchmarks:
concat 2 arrays: Array.prototype.concat vs spread operator
spread operator vs push Brian
spread operator vs push Brian2
Array.prototype.concat vs spread operator (fix)
zk test spread vs push
Comments
Confirm delete:
Do you really want to delete benchmark?