Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator - immutable push
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method and push
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
var collection = new Array(100); collection.fill(6); var value = 7; var result = collection.concat(value);
spread operator
var collection = new Array(100); collection.fill(6); var value = 7; var result = [...collection, value];
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:
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 dive into the explanation of the provided benchmark. **Benchmark Overview** The test compares two ways to add an element to an array in JavaScript: using the `Array.prototype.concat()` method and the spread operator (`...`). The benchmark is designed to measure which approach performs better for creating a new array with a single element. **Options Compared** There are two options being compared: 1. **`Array.prototype.concat()`**: This method concatenates one or more arrays into a new array, appending all the elements from each argument in the same order. 2. **Spread Operator (`...`)**: This operator is used to create a new array by spreading an existing array or value. **Pros and Cons** Here are some pros and cons of each approach: * **`Array.prototype.concat()`**: + Pros: more explicit, easier to understand for older JavaScript versions. + Cons: creates a new array with two elements (the original array and the element being added), which can be slower than spreading an existing array. * **Spread Operator (`...`)**: + Pros: more concise, faster, and more memory-efficient. + Cons: requires modern JavaScript versions (ECMAScript 2018+) and may not work in older browsers. **Library Used** There is no specific library used in this benchmark. The `Array.prototype.concat()` method is a built-in JavaScript method, while the spread operator (`...`) is also part of the ECMAScript standard. **Special JS Feature/Syntax** The benchmark uses modern JavaScript features: * Spread Operator (`...`): introduced in ECMAScript 2018+. * Template Literals (`\r\n...`): used for multiline strings. **Other Alternatives** For creating a new array with a single element, you can also use other methods like `Array([element])` or simply assign the element to an empty array `[]`. However, these alternatives may not be as concise or efficient as using the spread operator (`...`) or `Array.prototype.concat()`. **Benchmark Preparation Code** The benchmark preparation code is intentionally left blank (`"Script Preparation Code": null`, `"Html Preparation Code": null`), which means that the test relies on the JavaScript engine's built-in behavior and does not require any additional setup or initialization.
Related benchmarks:
Array.prototype.concat vs spread operator
Array.prototype.concat vs Spread operator
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator (fix)
Array.prototype.concat vs spread operator real
Comments
Confirm delete:
Do you really want to delete benchmark?