Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Arguments Copy Array
(version: 0)
Comparing performance of:
Slice vs Dots
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function sliceCopy() { return Array.prototype.slice.call(arguments, 0); } function dotsCopy() { return [...arguments]; }
Tests:
Slice
sliceCopy("A","B","C","D","E","F")
Dots
dotsCopy("A","B","C","D","E","F")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Slice
Dots
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/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15
Browser/OS:
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Slice
3477137.0 Ops/sec
Dots
8329414.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **Benchmark Definition JSON** The provided JSON represents a benchmark named "Arguments Copy Array". This benchmark is designed to test how efficient JavaScript engines are when copying arrays using different methods. **Script Preparation Code** The script preparation code defines two functions: `sliceCopy` and `dotsCopy`. These functions take an arbitrary number of arguments and return a new array by either using the `Array.prototype.slice.call()` method or the spread operator (`...`) with the `arguments` object, respectively. **Purpose of Library** In this benchmark, we don't see any explicit library usage. However, it's worth noting that JavaScript engines are built on top of ECMAScript standards, which provide a set of libraries and APIs for various tasks, including array copying. **Options Compared** The two options being compared in this benchmark are: 1. **`Array.prototype.slice.call(arguments, 0)`**: This method uses the `slice()` function to create a new array with the specified elements, starting from index 0. 2. **`[...arguments]`**: This syntax uses the spread operator (`...`) to create a new array by iterating over the `arguments` object. **Pros and Cons** Here's a brief overview of each approach: 1. **`Array.prototype.slice.call(arguments, 0)`**: * Pros: More explicit control over the copying process. * Cons: May be slower due to the additional function call overhead. 2. **`[...arguments]`**: * Pros: Cleaner and more concise syntax. * Cons: May have performance implications due to the creation of a new array. In general, `Array.prototype.slice.call(arguments, 0)` is considered a more verbose approach that can lead to slower execution times, while `[...arguments]` is often preferred for its brevity and readability. **Special JS Features** The benchmark doesn't use any special JavaScript features or syntax beyond what's standard in ECMAScript. No modern features like async/await, Promises, or generators are employed here. **Other Alternatives** For array copying, you might also consider using the following alternatives: * `Array.from(arguments)` (ECMAScript 2015+): Similar to `[...arguments]`, but with a more explicit `from` argument. * `new Array(arguments.length).fill().map((_, i) => arguments[i])` (ECMAScript 2015+): A more verbose approach that creates a new array with the same length as the original, and then maps each element from the `arguments` object. However, these alternatives might not be as concise or efficient as the `[...arguments]` syntax. **Benchmark Preparation Code** The provided preparation code is quite simple and straightforward. It defines two functions that take an arbitrary number of arguments and return a new array using either the `slice()` method or the spread operator. This allows for easy comparison between different execution scenarios. Overall, this benchmark provides a good starting point for measuring the performance differences between various JavaScript array copying methods, making it useful for identifying potential optimization opportunities in your own codebase.
Related benchmarks:
Array clone
Array cloning: slice vs spread
JavaScript array copy via spread op vs slice
Shallow Copy Array
Array.prototype.slice vs spread operator for copying
Comments
Confirm delete:
Do you really want to delete benchmark?