Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array concat vs spread operator vs push for geojson line string geometry
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method and push
Comparing performance of:
Array.prototype.concat vs spread operator vs Push
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
var params = [ [1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10] ]; var params2 = [ [1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10] ]; var other = params.concat(params2);
spread operator
var params = [ [1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10] ]; var params2 = [ [1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10] ]; var other = [ ...params, ...params2 ];
Push
var params = [ [1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10] ]; var params2 = [ [1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],[1, 2], [3, 4], [5, 6], [7, 8], [9, 10] ]; var other = params.push(...params2);
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 the benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark measures the performance of three different ways to concatenate arrays in JavaScript: 1. `Array.prototype.concat()` 2. The spread operator (`...`) 3. `push()` with multiple arguments **Test Cases** There are 15 test cases, but only three unique methods are being compared: `concat()`, spread operator, and `push()`. ### Array.prototype.concat() `concat()` is a method that concatenates two or more arrays and returns a new array. The test case creates two identical arrays, `params` and `params2`, with many repeated elements. **Pros:** * Well-established method * Simple to implement **Cons:** * Creates a new array, which can be memory-intensive for large inputs * May not perform well on older browsers or systems with limited memory ### Spread Operator (`...`) The spread operator is a relatively new feature introduced in ES6. It allows you to expand an array into individual elements or objects. **Pros:** * Efficient and concise way to concatenate arrays * Does not create a new array, preserving the original array's structure **Cons:** * May not work well with older browsers or systems that do not support ES6 * Can be less readable for developers unfamiliar with the syntax ### Push() `push()` is another method that concatenates an array by adding one or more elements to the end. **Pros:** * Fast and efficient way to append elements to an array * Does not create a new array, preserving the original array's structure **Cons:** * Requires multiple function calls for each element (e.g., `push(...)`), which can be slower than `concat()` or spread operator **Benchmark Results** The latest benchmark results show that: 1. The spread operator is the fastest method, with an execution rate of 1691641.25 executions per second. 2. `Push()` comes in second, with a lower execution rate (961173.6875). 3. `Array.prototype.concat()` has the lowest execution rate (852747.0625). **Other Alternatives** If you need to concatenate arrays, consider using: * `reduce()`: a method that concatenates an array by reducing it to a single value. * `flat()`: a method that flattens an array of arrays into a single array. However, these methods may have different performance characteristics and use cases compared to the three methods being benchmarked.
Related benchmarks:
ES6 Array concat vs spread operator
Array concat vs spread operator vs push larger list
Array.prototype.concat vs spread operator real
zk test spread vs push
Array.prototype.concat vs spread operator 12
Comments
Confirm delete:
Do you really want to delete benchmark?