Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator vs push
Created:
8 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
var params = [ "hello", true, 7 ] var other = params.concat(1);
spread operator
var params = [ "hello", true, 7 ] var other = [ ...params, 1]
push
var other = [ "hello", true, 7 ] other.push(1)
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):
Let's break down what's being tested in this benchmark. **Benchmark Definition** The benchmark is comparing three approaches for concatenating arrays: 1. `Array.prototype.concat()` 2. The new ES6 spread operator (`[ ...params, 1]`) 3. Using the `push()` method to add an element to the end of the array (`other.push(1)`) **Options Compared** The benchmark is comparing two main options: * `Array.prototype.concat()`: a traditional way of concatenating arrays using the `concat()` method. * The new ES6 spread operator (`[ ...params, 1]`): a concise and modern way of creating a new array by spreading elements from an existing array. **Pros and Cons** Here are some pros and cons of each approach: * **Array.prototype.concat()**: + Pros: widely supported, easy to understand. + Cons: can be slower than the spread operator for large arrays, may involve unnecessary copying. * **New ES6 spread operator (`[ ...params, 1]`)**: + Pros: faster and more memory-efficient than `concat()`, concise syntax. + Cons: requires modern JavaScript engines (ES6+) to support it. **Library** None of the benchmarked methods use a third-party library. The focus is on comparing the performance of these built-in JavaScript features. **Special JS Feature or Syntax** The ES6 spread operator (`[ ...params, 1]`) is a new feature introduced in ECMAScript 2015 (ES6). It's not widely supported in older browsers or JavaScript engines. **Other Alternatives** If you're interested in exploring other approaches to concatenating arrays, some alternatives include: * Using the `Array.prototype.push()` method with two arguments (`other.push(1)`): this is similar to using `concat()`, but can be slightly faster. * Creating a new array using the `Array.from()` method: `new Array(3).fill().map(() => ({ value: params[0] }, 1, true)).flat(1, Infinity).push(1)` Keep in mind that these alternatives may have different performance characteristics and are not as concise as the spread operator. Overall, this benchmark provides a simple and controlled comparison of three common approaches to concatenating arrays in JavaScript.
Related benchmarks:
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator (fix)
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?