Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Function arguments list vs object
(version: 0)
Comparing performance of:
List vs Object
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var input = { foo: 1, bar: 2 };
Tests:
List
const foo = (bar, qux) => null; const { bar, qux } = input; foo(bar, qux);
Object
const foo = ({ bar, qux }) => null; const { bar, qux } = input; foo({ bar, qux });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
List
Object
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_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
List
79051704.0 Ops/sec
Object
25874720.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmark and its test cases. **What is being tested?** MeasureThat.net is testing two approaches for passing function arguments in JavaScript: 1. **List**: Passing arguments as an array or list (e.g., `foo([bar, qux])`). 2. **Object**: Passing arguments as an object (e.g., `foo({ bar: 1, qux: 2 })`). **Options being compared** The benchmark is comparing the execution performance of these two approaches. **Pros and Cons of each approach** * **List**: + Pros: Typically faster and more efficient, as it allows the compiler or interpreter to optimize the function call. + Cons: May not be compatible with all libraries or frameworks that expect objects as arguments. * **Object**: + Pros: More compatible with modern JavaScript libraries and frameworks that expect objects as arguments. + Cons: May be slower due to additional overhead of parsing and processing object literals. **Special considerations** In the benchmark, special attention is given to the use of destructuring assignment (`{ bar, qux } = input;`) in both test cases. This syntax allows for more concise code and is a common pattern in modern JavaScript development. **Other alternatives** There are other ways to pass function arguments, such as: * Using a separate array or object literal: `foo([bar, qux])` or `foo({ bar: 1, qux: 2 })`. * Using the spread operator (`...`) to merge objects: `foo({...input.bar, ...input.qux})`. * Using a function with variable arguments (e.g., `foo(...args)`) followed by destructuring assignment. However, these alternatives are not part of the benchmark's focus and are not tested in this specific example.
Related benchmarks:
arrow vs bind
.bind() vs function
new Function vs Literal
function vs new function
Arrow function vs bind function creation
Comments
Confirm delete:
Do you really want to delete benchmark?