Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Rest parameters vs array parameter
(version: 0)
Comparing performance of:
Rest vs Array
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Rest
const f = (a, ...b) => a.concat(b.map(String)) const r = f([0], 1, 2, 3, 4, 5);
Array
const f = (a, b) => a.concat(b.map(String)) const r = f([0], [1, 2, 3, 4, 5]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Rest
Array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Android 16; Mobile; rv:148.0) Gecko/148.0 Firefox/148.0
Browser/OS:
Firefox Mobile 148 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Rest
10519207.0 Ops/sec
Array
10669770.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is tested?** The provided benchmark tests two approaches to passing multiple arguments to a function: using rest parameters (e.g., `...b`) and using an array as a parameter (e.g., `[1, 2, 3, 4, 5]`). **Options compared** Two options are being compared: 1. **Rest parameters**: This approach uses the `...` syntax to capture all remaining arguments into an array-like object called the "rest" parameter. 2. **Array parameter**: This approach passes the argument as a separate array. **Pros and Cons of each approach** **Rest Parameters:** Pros: * More concise and expressive code * Avoids the need for explicit `concat` or array manipulation Cons: * Can be slower due to the overhead of creating an object with dynamic properties * May have performance issues if used excessively, as it can lead to a lot of temporary objects being created **Array Parameter:** Pros: * Faster execution speed, as arrays are typically more efficient than objects * Less memory allocation, as arrays do not create temporary objects Cons: * Requires more code and is less concise * May be more error-prone if the wrong type of argument is passed (e.g., an array instead of a variable number of arguments) **Library usage** There doesn't appear to be any libraries being used in this benchmark. **Special JS features or syntax** The `map` function is used to transform each element in the array, which is a common pattern in JavaScript. The `String` function is used as the mapping function, but it's not relevant to the rest parameters vs. array parameter comparison. **Benchmark preparation code and HTML Preparation Code** The provided benchmark definition includes script preparation code that defines two functions: `f` with rest parameters and `f` with an array parameter. There is no corresponding HTML preparation code. **Other alternatives** There are a few other ways to pass multiple arguments to a function in JavaScript: * Using the spread operator (`...`): This can be used in combination with the rest parameter syntax or as an alternative to using arrays. * Using `arguments`: This is an array-like object that contains all arguments passed to the function. * Using destructuring: This can be used to extract specific values from the argument list, but it's not relevant to this benchmark. Overall, the provided benchmark tests the performance difference between two approaches to passing multiple arguments to a JavaScript function.
Related benchmarks:
push vs unshift
Array constructor vs literal performance, 12345
array.toString vs `${array}`
Array.from() vs []
Array() vs new Array() fill
Comments
Confirm delete:
Do you really want to delete benchmark?