Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.concat vs native array spread
(version: 0)
Comparing performance of:
Array spread (small arrays) vs Array spread (big arrays) vs Array.concat (small arrays) vs Array.concat (big arrays)
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Array spread (small arrays)
const a = [1, 2]; const b = [true, 'hello', 7]; const c = [...a, ...b];
Array spread (big arrays)
const a = (new Array(1000)).fill(0); const b = (new Array(1000)).fill(1); const c = [...a, ...b];
Array.concat (small arrays)
const a = [1, 2]; const b = [true, 'hello', 7]; const c = a.concat(b);
Array.concat (big arrays)
const a = (new Array(1000)).fill(0); const b = (new Array(1000)).fill(1); const c = a.concat(b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Array spread (small arrays)
Array spread (big arrays)
Array.concat (small arrays)
Array.concat (big arrays)
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 provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark measures the performance of two JavaScript array methods: `Array.prototype.concat()` and the spread operator (`...`). **Options Compared** There are four test cases: 1. **Small arrays**: The first two test cases use small arrays with a fixed length ( `[1, 2]`, `[true, 'hello', 7]`) to create two separate arrays and then concatenate them using both methods. * `Array.prototype.concat()` * Spread operator (`...`) 2. **Big arrays**: The last two test cases use large arrays filled with zeros or ones ( `(new Array(1000)).fill(0)`, `(new Array(1000)).fill(1)` ) to create two separate arrays and then concatenate them using both methods. **Pros and Cons** * **Array.prototype.concat()**: + Pros: More predictable behavior, better support for older browsers. + Cons: May be slower due to the need to create a new array and perform additional checks. * **Spread operator (`...`)**: + Pros: Faster, more efficient, and easier to read. It also creates a new array without modifying the original arrays. + Cons: Requires JavaScript 7+, may not work in older browsers. **Library/Functionality Used** The `concat()` method is a native JavaScript function that concatenates two or more arrays. The spread operator (`...`) is a feature introduced in ECMAScript 2015 (ES6) to create a new array by spreading the elements of an existing array. **Special JS Feature/Syntax** * The spread operator (`...`), as mentioned earlier, was introduced in ES6 and is not supported in older browsers. **Other Alternatives** If you need to concatenate arrays, you can also use other methods like `Array.prototype.push()` or libraries like Lodash. However, the spread operator is generally considered a more efficient and concise solution. Keep in mind that the choice of method depends on your specific use case, performance requirements, and target browser support.
Related benchmarks:
concat vs unshift vs spread
simple spread vs concat benchmark
unshift vs spread vs concat
.concat vs. spread
Concat vs Spread for Large Arrayss
Comments
Confirm delete:
Do you really want to delete benchmark?