Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
spread vs concat vs unshift Big string array
(version: 0)
spread vs concat vs unshift
Comparing performance of:
arrayUnshift123 vs arrayConcat123 vs arraySpread123
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = ['first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth','first','second','third','fourth'];
Tests:
arrayUnshift123
array.unshift(0);
arrayConcat123
array = array.concat([0])
arraySpread123
array = [0, ...array]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
arrayUnshift123
arrayConcat123
arraySpread123
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):
I'll break down the provided benchmark and its components. **Benchmark Definition JSON** The provided `benchmark definition` json represents a set of test cases to measure the performance of JavaScript array operations. There are three main test cases: 1. **array.unshift(0)**: This test case measures the performance of the `unshift()` method, which adds an element at the beginning of an array. 2. **array = array.concat([0])** : This test case measures the performance of the `concat()` method, which concatenates two or more arrays and returns a new array. 3. **array = [0, ...array]**: This test case measures the performance of the spread operator (`...`), which creates a new array by spreading the elements of an existing array. **Options Compared** The benchmark compares the performance of three different approaches: 1. `unshift()` 2. `concat()` 3. Spread operator (`...`) **Pros and Cons** Here's a brief overview of each approach's pros and cons: * **`unshift()`**: Pros: * Can be more efficient than `concat()` because it modifies the original array instead of creating a new one. * Can be faster for small arrays due to cache locality benefits. * **`concat()`**: Pros: * More flexible and widely supported than `unshift()`. * Can handle large arrays by creating a new array without modifying the original one. * **Spread Operator (`...`)**: Pros: * Elegant syntax for creating a new array from an existing one. * Can be faster than `concat()` when dealing with small arrays due to its lower overhead. Cons: * `unshift()` and `concat()` both create a new array, which can lead to memory allocation overhead. * The spread operator creates a new array by spreading the elements of an existing array, which can also lead to memory allocation overhead if the original array is large. **Individual Test Cases** The benchmark provides three individual test cases: 1. **arrayUnshift123**: Measures the performance of `unshift()` with a specific input. 2. **arrayConcat123**: Measures the performance of `concat()` with a specific input. 3. **arraySpread123**: Measures the performance of the spread operator (`...`) with a specific input. **Latest Benchmark Result** The latest benchmark result provides the execution counts per second for each test case across different devices and browsers: | TestName | ExecutionsPerSecond | | --- | --- | | arrayUnshift123 | 34670.03515625 | | arrayConcat123 | 955.455322265625 | | arraySpread123 | 185.38943481445312 | This result indicates that `unshift()` is the fastest approach, followed by the spread operator (`...`), and then `concat()`. However, it's essential to consider the specific use case, input size, and other factors that may affect performance.
Related benchmarks:
JSON stringification versus simple map
Array.from vs Array spread with mapping of values2
Array Spread operator vs Push vs Concat in reduce
index vs map111
Comments
Confirm delete:
Do you really want to delete benchmark?