Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
concat vs spread with js array testing 1.2.3.
(version: 0)
Comparing performance of:
concat vs spread
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
concat
var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].concat(params);
spread
var params = [ "hello", true, 7 ] var other = [ 1, 2, ...params ]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
concat
spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
concat
17578226.0 Ops/sec
spread
82888840.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definition and test cases to explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Definition** The benchmark is defined by a JSON object with several properties: * `Name`: The name of the benchmark, which is "concat vs spread with js array testing 1.2.3." * `Description`: An empty string indicating no description for this benchmark. * `Script Preparation Code` and `Html Preparation Code`: Empty strings indicating no specific code needs to be prepared or executed before running the benchmark. **Individual Test Cases** There are two test cases: ### 1. "concat" The benchmark definition is: ```javascript var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].concat(params); ``` This code creates an array `params` with three elements: a string `"hello"`, a boolean `true`, and an integer `7`. Then, it concatenates the `params` array to another existing array `[ 1, 2 ]` using the `concat()` method. ### 2. "spread" The benchmark definition is: ```javascript var params = [ "hello", true, 7 ]; var other = [ 1, 2, ...params ]; ``` This code creates an array `params` with three elements: a string `"hello"`, a boolean `true`, and an integer `7`. Then, it spreads the `params` array using the spread operator (`...`) to create a new array that includes all elements from `[ 1, 2 ]` followed by all elements from `params`. **Comparison** The benchmark compares the performance of these two approaches: * `concat()`: Concatenates an existing array with another array. * `spread()` (using the spread operator): Spreads the elements of one array into another. **Pros and Cons** * **Concat()**: + Pros: Can be used when you need to add multiple arrays or objects together. + Cons: Creates a new array, which can lead to increased memory usage and potentially slower performance. * `spread()` (using the spread operator): + Pros: More concise and readable than concatenation. Reduces memory allocation overhead. + Cons: May not be as efficient for large datasets due to potential overhead of creating a new array. **Library** None are mentioned in this benchmark, but it's common for benchmarks like these to test JavaScript engine optimizations that may rely on specific library implementations (e.g., WebAssembly or other just-in-time compilation techniques). **Special JS Features/Syntax** No special features or syntax are used in this benchmark. The `...` spread operator is a standard feature introduced in ECMAScript 2015 (ES6), and the `concat()` method has been available since older versions of JavaScript. **Alternatives** Other alternatives for array concatenation and spreading include: * Using `Array.prototype.push()`: Instead of concatenating arrays, you can add elements to an existing array using `push()`. * Using `Array.prototype.unshift()`: Alternatively, you can add elements to the beginning of an array using `unshift()`. Keep in mind that performance differences between these approaches are typically minimal and may not be noticeable for most use cases. However, this benchmark aims to test specific optimization techniques or engine implementations that might exhibit different behavior under certain conditions.
Related benchmarks:
Array.prototype.concat vs Spread operator
unshift vs spread vs concat
Array.prototype.concat vs spread operator (new try)
Array.prototype.concat vs spread operator (fix)
spread vs concat vs unshift on 100000
Comments
Confirm delete:
Do you really want to delete benchmark?