Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
function vs arrow
(version: 0)
Comparing performance of:
function vs arrow vs arrow-direct vs arrow-direct2
Created:
7 years ago
by:
Guest
Jump to the latest result
Tests:
function
const array = [1, 2, 3, 4, 5]; const filtered = array.filter(function(d) { return d % 2 === 0; });
arrow
const array = [1, 2, 3, 4, 5]; const filtered = array.filter((d) => { return d % 2 === 0; });
arrow-direct
const array = [1, 2, 3, 4, 5]; const filtered = array.filter(d => d % 2 === 0);
arrow-direct2
const array = [1, 2, 3, 4, 5]; const filtered = array.filter((d) => d % 2 === 0);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
function
arrow
arrow-direct
arrow-direct2
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
function
80183896.0 Ops/sec
arrow
81839472.0 Ops/sec
arrow-direct
79919464.0 Ops/sec
arrow-direct2
79430648.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark is comparing three different approaches to filter an array in JavaScript: 1. **Function**: Using a traditional `function` with the `filter()` method, where the callback function takes a single argument (`d`) and returns a boolean value. 2. **Arrow Function (Direct)**: Using an arrow function with the `filter()` method, where the lambda expression `(d) => { ... }` is equivalent to a traditional function definition. 3. **Arrow Function (Indirect)**: This option seems to be missing from the original benchmark, but based on common usage, it would use an arrow function as a callback function inside another function. **What's being compared?** The tests are comparing the performance of these three approaches in filtering an array of 5 elements. The `filter()` method is used with different implementation styles: traditional function, arrow function (both direct and indirect). **Options comparison** * **Function**: This approach uses a traditional function definition, which can be more verbose but still effective. + Pros: - Easy to understand and read - Can be easily debugged or optimized + Cons: - May be slower due to the overhead of creating a new scope * **Arrow Function (Direct)**: This approach uses an arrow function with the `filter()` method, which is concise and expressive. + Pros: - More concise than traditional functions - Can reduce code duplication + Cons: - May be less readable for some developers due to the lambda syntax * **Arrow Function (Indirect)**: This option seems missing from the original benchmark, but it would use an arrow function as a callback function inside another function. **Library usage** There is no explicit library used in these tests. However, `filter()` is a built-in method of the Array prototype in JavaScript. **Special JS feature or syntax** The test uses arrow functions (both direct and indirect), which is a modern JavaScript feature introduced in ECMAScript 2015. This allows for concise and expressive code by removing the need to declare a separate function scope. **Other alternatives** If you were to add additional alternatives, you might consider: * **Lodash**: A popular utility library that provides a `filter()` method among other functionalities. * **ES6-ified functions**: Using modern JavaScript features like `map()`, `reduce()`, and `forEach()` to filter arrays in a different way. Keep in mind that the choice of approach depends on your specific use case, personal preference, and project requirements.
Related benchmarks:
Arrow function vs normal function comparison fixed
Noop vs new arrow function calls
Arrow function vs normal function comparison 2
Arrow function vs function comparison
Arrow functions vs functions
Comments
Confirm delete:
Do you really want to delete benchmark?