Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
дед наебал
(version: 0)
Comparing performance of:
indexed vs destruct vs spread
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
indexed
function add(...rest) { return rest.reduce((a,b) => a + b, 0); } var arr = Array.from({length: 10000}, (_, i) => ([i, i+1, i+2, i+3, i+4])) var xs = arr.map(nums => add(nums[0], nums[1], nums[2], nums[3], nums[4]))
destruct
function add(...rest) { return rest.reduce((a,b) => a + b, 0); } var arr = Array.from({length: 10000}, (_, i) => ([i, i+1, i+2, i+3, i+4])) var xs = arr.map(([a,b,c,d,e]) => add(a,b,c,d,e))
spread
function add(...rest) { return rest.reduce((a,b) => a + b, 0); } var arr = Array.from({length: 10000}, (_, i) => ([i, i+1, i+2, i+3, i+4])) var xs = arr.map(nums => add(...nums))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
indexed
destruct
spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 16 on iOS 16.6
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
indexed
3423.0 Ops/sec
destruct
1086.5 Ops/sec
spread
1534.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents three benchmark test cases on MeasureThat.net, which measures the performance of JavaScript microbenchmarks. The benchmarks are designed to evaluate the performance of different approaches to function argument spreading in JavaScript. **Benchmark Definitions** Each benchmark definition consists of a single script that defines a function `add` and creates an array `arr` with 10,000 elements each containing five numbers. The arrays are then mapped over using three different methods: 1. **Indexed**: The function `add` is called with the individual elements as arguments, using the syntax `add(nums[0], nums[1], nums[2], nums[3], nums[4])`. 2. **Destructured**: The function `add` is called with destructured arguments, using the syntax `[a,b,c,d,e] = nums; add(a,b,c,d,e)`. 3. **Spread**: The function `add` is called with spread syntax, using the syntax `add(...nums)`. **Options Compared** The three benchmark test cases compare the performance of three different approaches to function argument spreading in JavaScript: * **Indexed**: This approach uses individual elements as arguments. * **Destructured**: This approach uses destructuring to extract values from arrays and then passes them to the `add` function. * **Spread**: This approach uses the spread syntax to pass an array of elements to the `add` function. **Pros and Cons** Here are some pros and cons for each approach: * **Indexed**: * Pros: Simple, easy to read, and well-established. * Cons: May be slower due to the overhead of indexing into arrays. * **Destructured**: * Pros: Can be faster than indexed because it avoids the overhead of array indexing. It's also a more modern and concise way to pass arguments to functions. * Cons: Requires careful handling of variable names and may be less readable for some developers. * **Spread**: * Pros: Concise, easy to read, and takes advantage of modern JavaScript features. * Cons: May be slower than destructured because it creates an intermediate array. **Library Usage** There are no libraries used in the benchmark test cases. The `Array.from` method is a built-in JavaScript method for creating arrays from iterables. **Special JS Features or Syntax** The benchmark test cases use modern JavaScript features such as: * **Destructuring**: This feature allows you to extract values from arrays and pass them to functions. * **Spread syntax**: This feature allows you to pass an array of elements to a function using the `...` operator. **Alternatives** If you're interested in exploring alternative approaches to function argument spreading, here are some options: * **Rest parameters**: Instead of using spread syntax or destructuring, you can use rest parameters (`...args`) to accept any number of arguments. * **Arrow functions**: You can define arrow functions with multiple arguments and pass them directly to other functions. * **Function composition**: You can compose functions together to create new functions that take multiple arguments. Keep in mind that the choice of approach depends on your specific use case, personal preference, and performance requirements.
Related benchmarks:
ruse compiler factorial 002
ruse compiler factorial 003
ruse compiler factorial 010
Triangular RV
Factorial math
Comments
Confirm delete:
Do you really want to delete benchmark?