Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
push, concat, spread on a simple array
(version: 0)
Comparing performance of:
push vs concat vs spread
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
push
var array = ["val1", "val2", "val2", "val4", "val5", "val6", "val7", "val8"]; array.push("val9");
concat
var array = ["val1", "val2", "val2", "val4", "val5", "val6", "val7", "val8"]; array.concat(array, "val9");
spread
var array = ["val1", "val2", "val2", "val4", "val5", "val6", "val7", "val8"]; array = [...array, "val9"];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
push
concat
spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
push
35044408.0 Ops/sec
concat
2642395.0 Ops/sec
spread
23999042.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided benchmark. **Benchmark Overview** The benchmark measures the performance of three different approaches: `push`, `concat`, and `spread` on a simple array of strings. The goal is to determine which approach is the fastest. **Options Compared** 1. **Push**: This method uses the `array.push()` method to append a new element to the end of the array. 2. **Concat**: This method uses the `array.concat()` method with an additional argument to concatenate two arrays (in this case, the original array and an array containing a single element). 3. **Spread**: This method uses the spread operator (`...`) to create a new array by copying elements from the original array and appending a new element. **Pros and Cons of Each Approach** 1. **Push**: * Pros: Simple and straightforward, no additional memory allocation or concatenation is required. * Cons: May involve more overhead due to the need to increment the length property of the array, which can lead to slower performance in some browsers. 2. **Concat**: * Pros: Can be faster than `push` because it avoids incrementing the length property of the array. However, it requires additional memory allocation and concatenation, which can introduce overhead. * Cons: Requires an additional method call (`concat()`), which may lead to slower performance due to the overhead of function calls. 3. **Spread**: * Pros: Can be faster than `push` because it avoids incrementing the length property of the array and only requires a single expression. * Cons: May require more memory allocation due to the creation of a new array, which can lead to slower performance. **Library Usage** None of the benchmark cases use any libraries or external dependencies. The tests only involve basic JavaScript features. **Special JS Features or Syntax** The benchmark uses some older JavaScript syntax, such as: * `var` declarations (instead of `let` or `const`) * The `push()` method (which is still supported in modern browsers) * The `concat()` method (which is also still supported in modern browsers) However, it's worth noting that the benchmark does not use any newer JavaScript features such as arrow functions, template literals, or async/await. **Alternatives** If you wanted to create a similar benchmark, you could consider testing other approaches, such as: * Using `Array.prototype.set()` instead of `push()` * Using `Array.prototype.splice()` instead of `concat()` * Using `Array.prototype.push.apply()` instead of `push()` * Using modern JavaScript features like `for...of` loops or `map()`/`filter()` methods Keep in mind that the performance differences between these approaches may vary depending on the browser and JavaScript engine being used.
Related benchmarks:
Array concat comparison between spread concat and push
simple spread vs concat benchmark
js array push,spread,concat single item
spread vs concat vs unshift vs push
Concat vs Push vs Spread Benchmark
Comments
Confirm delete:
Do you really want to delete benchmark?