Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
converting arguments to Array
(version: 0)
[].slice.call versus [].push.apply
Comparing performance of:
baseline (main) vs current (PR)
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function runLoop(fn) { for (let i = 1000; i--; ) { fn("bacon", "egg", "spam"); } }
Tests:
baseline (main)
function makeArray() { return Array.prototype.slice.call(arguments); } runLoop(makeArray);
current (PR)
function makeArray() { var _args; return (_args = []).push.apply(_args, arguments), _args; } runLoop(makeArray);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
baseline (main)
current (PR)
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; WOW64; Trident/7.0; rv:11.0) like Gecko
Browser/OS:
IE 11 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
baseline (main)
1704.7 Ops/sec
current (PR)
1785.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the explanation for you. **Benchmark Definition** The provided JSON represents a benchmark test on MeasurThat.net, which compares two different approaches to convert arguments to an array in JavaScript. In this specific benchmark, we have: 1. `[] .slice.call(arguments)`: This approach uses the `slice()` method of the Array prototype, which returns a shallow copy of a portion of the original array. The arguments are passed as an array, and `slice()` is used to extract them. 2. `[] .push.apply(arguments)`: This approach uses the `push()` method of the Array prototype and applies it to all elements in the array using `apply()`. The result is an array with the same elements. **Options Comparison** The two approaches have different performance characteristics: * **`slice.call(arguments)`**: This method has a relatively low overhead, as it only requires a single function call and returns a new array. However, it can be slower for large input arrays due to the creation of a new array object. * **`.push.apply(arguments)`**: This approach is generally faster than `slice.call()` because it uses a more optimized implementation of the `push()` method, which only requires a single iteration over the arguments. **Pros and Cons** Here's a brief summary: * **`slice.call(arguments)`**: + Pros: Low overhead, easy to read. + Cons: Can be slower for large input arrays due to array object creation. * **`.push.apply(arguments)`**: + Pros: Generally faster, optimized implementation of `push()` method. + Cons: May have higher overhead due to function call and array iterator. **Other Considerations** In modern JavaScript, both approaches are relatively fast and efficient. However, if you're working with large input arrays, the performance difference between these two methods might be noticeable. Additionally, some libraries or frameworks might optimize one approach over the other, so it's essential to consider the specific use case and requirements. **Library Usage** There is no explicit library mentioned in the provided benchmark definition. However, if you're familiar with popular JavaScript libraries, you might recognize `Array.prototype.slice.call()` as a polyfill for older browsers or environments where `slice()` is not supported natively. **Special JS Features or Syntax** The test doesn't use any special features or syntax that would require additional explanation. The focus is on comparing two standard Array methods. I hope this explanation helps you understand the benchmark and its results better!
Related benchmarks:
Array.prototype.slice vs spread operator 12
sliceeee
Array.prototype.slice vs spread operator part 2000: electric boogaloogaloogaloogaloo
Arguments to Array - by Jeeeyul
Comments
Confirm delete:
Do you really want to delete benchmark?