Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
rest parameters vs arguments (no extra args)
(version: 0)
Comparing performance of:
arguments vs rest parameter
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.els = []; function t1() { window.els.push(...arguments); } function t2(...args) { window.els.push(...args); }
Tests:
arguments
window.els.length = 0; for (let i = 0; i < 2000; i++) { if (i % 3 === 0) { els.push(t1('div', {class: 'foo'}, i, i + 1, i + 2)); } else { els.push(t1('div', {class: 'foo'}, i)); } }
rest parameter
window.els.length = 0; for (let i = 0; i < 2000; i++) { if (i % 3 === 0) { els.push(t2('div', {class: 'foo'}, i, i + 1, i + 2)); } else { els.push(t2('div', {class: 'foo'}, i)); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
arguments
rest parameter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 137 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
arguments
2627.5 Ops/sec
rest parameter
2775.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition** The provided JSON represents a benchmark definition with two test cases: "rest parameters vs arguments (no extra args)". This benchmark tests the performance difference between using regular arguments and rest parameters in JavaScript functions. **Options Compared** In this benchmark, we have two options: 1. **Arguments**: The traditional way of passing arguments to a function. 2. **Rest Parameters**: A feature introduced in ECMAScript 2015 (ES6) that allows for the explicit use of a parameter list with a rest operator (`...`) after all other parameters. **Pros and Cons** ### Arguments Pros: * Widely supported and used in existing codebases * Simple to understand and implement Cons: * Less efficient than rest parameters due to unnecessary parameter checking and processing ### Rest Parameters Pros: * More concise and expressive syntax * Can improve code readability and maintainability Cons: * May be less intuitive for developers without experience with rest parameters * Requires support from all browsers and environments **Library Usage** In the provided benchmark definition, we see that the `t1` function uses `arguments`, while the `t2` function uses rest parameters (`...args`). The `els` array is used to store the results of each function call. The `window.els.push()` method is likely a custom implementation or a placeholder for a more robust logging mechanism. Its purpose is not directly related to the performance comparison being tested. **Special JS Features** There are no special JavaScript features or syntaxes mentioned in this benchmark that require additional explanation. The use of rest parameters is standard and widely supported in modern JavaScript environments. **Other Alternatives** If you're interested in exploring alternative approaches to benchmarking JavaScript performance, consider the following options: * **V8 Benchmark Suite**: A set of microbenchmarks designed to test specific aspects of V8, such as garbage collection, string processing, and more. * **jsPerf**: A tool for benchmarking JavaScript code performance in various browsers and environments. * **BenchmarkJS**: A framework for writing and running JavaScript benchmarks, providing a simple and consistent API for testing different scenarios. By considering these alternatives and understanding the specific options being tested (arguments vs. rest parameters), you can gain insights into the performance characteristics of your own JavaScript codebases.
Related benchmarks:
Array .push() vs .unshift() + ref to last
Noop vs new arrow function call
Add new element to array (preparation): push vs destructuring vs bracket access
Array .push() vs .unshift() |
rest parameters vs arguments 3
Comments
Confirm delete:
Do you really want to delete benchmark?