Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
rest vs arguments
(version: 0)
Comparing performance of:
via rest vs via arguments
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function f(...xs){ for(let i=0, l=xs.length; i<l; ++i) xs[i]; } function g(){ for(let i=0, l=arguments.length; i<l; ++i) arguments[i]; }
Tests:
via rest
f(0,1,2,3,4,5,6,7,8,9)
via arguments
g(0,1,2,3,4,5,6,7,8,9)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
via rest
via arguments
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
via rest
60886076.0 Ops/sec
via arguments
59633648.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark definition and test cases. **What is being tested?** The benchmark tests two different ways to iterate over an array of numbers in JavaScript: using the `rest` parameter syntax (introduced in ECMAScript 2015) and the traditional `arguments` object. The test case "via rest" uses the `f` function with the `rest` parameter, while the test case "via arguments" uses the `g` function with the `arguments` object. **Options compared** The benchmark compares two options: 1. **Rest parameter syntax (`f` function)**: This is a modern JavaScript feature that allows functions to accept an arbitrary number of parameters using the `...` syntax. 2. **Traditional `arguments` object (`g` function)**: This is a legacy way of accessing function arguments in JavaScript. **Pros and cons** * **Rest parameter syntax (`f` function) Pros**: + More concise and expressive code + Easier to read and write + Less prone to errors (e.g., no need to worry about the number of arguments) * **Rest parameter syntax (`f` function) Cons**: + Only supported in modern browsers and JavaScript engines (not compatible with older versions) + May not work as expected in certain situations (e.g., when used with `apply()` or `bind()`) * **Traditional `arguments` object (`g` function) Pros**: + Wide browser and JavaScript engine support + More control over iteration (e.g., can use `length` property) + Can work with older versions of JavaScript * **Traditional `arguments` object (`g` function) Cons**: + Less concise and expressive code + More prone to errors (e.g., need to worry about the number of arguments) **Library usage** There is no library explicitly mentioned in the benchmark definition. However, it's worth noting that modern JavaScript engines often use techniques like Just-In-Time (JIT) compilation and caching to optimize function calls. These optimizations may affect the performance results. **Special JS feature or syntax** The benchmark does not mention any special JavaScript features or syntax beyond the rest parameter syntax. If you were using a newer feature like `async/await`, `promises`, or ES6 classes, it would be mentioned here. **Other alternatives** In this specific case, there are no other alternatives being tested besides the rest parameter syntax and traditional `arguments` object. However, if you wanted to test other iteration methods, such as: * Using a `for...of` loop * Using an array method like `forEach()` or `map()` * Using a library like Lodash's `each()` function These alternatives would be worth exploring in a different benchmarking context. Overall, this benchmark provides a clear comparison of two modern JavaScript features and their performance characteristics, helping developers understand the trade-offs between concise code and compatibility with older browsers and JavaScript engines.
Related benchmarks:
Lodash loop vs foreach vs map
Array loop vs foreach vs map vs for w/o fn call - with console.log
Array loop vs foreach vs map vs while
Array loop: forEach vs for vs map vs for of entries
Array loop vs foreach vs for_of
Comments
Confirm delete:
Do you really want to delete benchmark?