Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
arguments destructure vs parameters
(version: 1)
Comparing performance of:
arguments vs parameters
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function a() { let [q, w, e, r, t, y] = arguments return q + w + y + e + r + t + y } function b(q, w, e, r, t, y) { return q + w + y + e + r + t + y }
Tests:
arguments
for(let j = 500; j--;)a(1,2,3,4,5,6)
parameters
for(let j = 500; j--;)b(1,2,3,4,5,6)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
arguments
parameters
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; rv:133.0) Gecko/20100101 Firefox/133.0
Browser/OS:
Firefox 133 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
arguments
56925.1 Ops/sec
parameters
1776235.2 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The provided benchmark compares the performance of two different JavaScript function definition styles: using the arguments object versus using named parameters. ### Benchmark Overview 1. **Functions Tested**: - **Function `a`**: Uses the `arguments` object to handle a variable number of arguments. - **Function `b`**: Uses explicit named parameters to accept a fixed number of arguments. ### Test Cases The benchmark is set up with two specific test cases: - **Test Case 1: `arguments`** - Executes the function `a` 500 times with predefined values (1, 2, 3, 4, 5, 6). - **Test Case 2: `parameters`** - Executes the function `b` 500 times with the same predefined values. ### Pros and Cons - **Function Using `arguments` (Function `a`)**: - **Pros**: - Flexibility: It can accept any number of arguments, making it dynamic to various function calls. - Simplicity in some cases, as you don't need to define all parameters explicitly. - **Cons**: - Performance: Accessing the `arguments` object may be slower as it adds an extra layer of overhead. - Not as readable: Developers may find it less clear what arguments are expected compared to named parameters. - **Function Using Named Parameters (Function `b`)**: - **Pros**: - Performance: Named parameters typically execute faster as they are directly referenced. - Clarity: The function signature clearly indicates expected input, making the code more readable. - **Cons**: - Fixed number of arguments: It cannot accept more or fewer arguments than specified without causing errors. ### Benchmark Results The benchmark results show a significant difference in performance between the two approaches: - **Function `b` (parameters)** executed at approximately **543,612** executions per second. - **Function `a` (arguments)** executed at approximately **2,833** executions per second. ### Conclusions From the results, it's evident that using named parameters (`b`) drastically outperforms using the `arguments` object (`a`). ### Considerations and Alternatives While the benchmark compares these two specific methods, other alternatives include: - **Rest Parameters**: ES6 introduced rest parameters (`...args`) which allow a function to accept a variable number of arguments while providing cleaner syntax and better performance than the traditional `arguments` object. This is a modern alternative to consider when you need flexibility without compromising performance. - **Object Destructuring**: Another approach involves passing an object to a function and using destructuring to extract values. This combines the clarity of named parameters with the flexibility of accepting varying input, though it would require constructing an object each time the function is called. Overall, the choice between using the `arguments` object versus named parameters (and other alternatives) should consider both performance implications and code maintainability based on the specific use case.
Related benchmarks:
JS multiple parameters vs parameter object
JS multiple parameters vs parameter object 2
Arguments vs Objects
rest args vs no args
rest vs arguments
call self vs inline
function object vs function
let vs array 2
arguments.callee vs new.target vs function name vs variable
Comments
Confirm delete:
Do you really want to delete benchmark?