Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.slice vs spread operator (forked 2)
(version: 0)
Compare the new ES6 spread operator with the traditional slice() method
Comparing performance of:
Array.prototype.slice Array.prototype.concat vs spread operator
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.slice Array.prototype.concat
var params = [ "hello", true, 7 ]; var other = params.slice().concat([4, "world", false]);
spread operator
var params = [ "hello", true, 7 ] var other = [ ...params, 4, "world", false]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.prototype.slice Array.prototype.concat
spread operator
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
Browser/OS:
Firefox 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.prototype.slice Array.prototype.concat
9074098.0 Ops/sec
spread operator
12826432.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **Benchmark Definition Overview** The benchmark measures the performance difference between two approaches: 1. Using `Array.prototype.slice()` followed by `concat()` 2. Using the new ES6 spread operator (`[...array, ...newElements]`) These approaches are being compared on an array of string values, integers, and booleans. **Options Compared** The benchmark compares two options: * Option 1: `Array.prototype.slice()` followed by `concat()`. This is a traditional method used in JavaScript for creating a new array. * Option 2: Using the spread operator (`[...array, ...newElements]`). This is a newer method introduced in ES6 (EcmaScript 2015) that allows for more concise and expressive way of creating arrays. **Pros and Cons** Here are some pros and cons of each approach: 1. **Option 1: `Array.prototype.slice()` followed by `concat()`** * Pros: + Well-established method, widely supported across browsers. + Easy to understand and use for simple array manipulation. * Cons: + Less concise than the spread operator. + Can be slower due to the overhead of creating a new array object. 2. **Option 2: Spread Operator (`[...array, ...newElements]`)** * Pros: + More concise and expressive way of creating arrays. + Often faster than using `slice()` followed by `concat()`. * Cons: + May not be supported in older browsers (before ES6). + Can be less intuitive for developers unfamiliar with the spread operator. **Library Used** There is no explicit library used in this benchmark, but the use of the spread operator implies that the browser supports ECMAScript 2015 or later standards. **Special JS Feature/Syntax** The benchmark uses the spread operator (`[...array, ...newElements]`), which is a special syntax introduced in ES6. This feature allows for more concise array creation and manipulation, but may not be supported in older browsers. **Other Alternatives** If you're interested in exploring other alternatives, here are some additional approaches: * Using `Array.prototype.slice()` with an offset or length argument can also create a new array. * Using `Array.prototype.push()` to add elements to the end of the original array is another approach. Keep in mind that these alternative approaches may not be as concise or expressive as the spread operator, but can still achieve similar results.
Related benchmarks:
Array.prototype.slice vs spread operator.
Array.prototype.slice vs spread operator with length limit
Array.prototype.slice vs spread operator on a bigger array
Array.prototype.slice vs spread operator - large array 100000
Array.prototype.slice vs spread operator performance
Comments
Confirm delete:
Do you really want to delete benchmark?