Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Arrow function vs bind function vs _.bind function
(version: 0)
Comparing performance of:
Arrow function vs Bind function vs _.Bind function
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script>
Script Preparation code:
var rThis = function() { return this }; arrowFn = () => rThis; bindFn = rThis.bind(this); _bindFn = _.bind(rThis, this);
Tests:
Arrow function
bindFn()
Bind function
arrowFn()
_.Bind function
_bindFn()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Arrow function
Bind function
_.Bind function
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 18 on iOS 18.5
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Arrow function
436332864.0 Ops/sec
Bind function
432231136.0 Ops/sec
_.Bind function
351230144.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested, compared, and discussed. **Benchmark Overview** The benchmark compares three different approaches to create an arrow function: using `bind()` from JavaScript, using `bind()` from the Underscore.js library (`_`), and creating a plain arrow function (`=>`). The goal is to determine which approach provides the best performance in terms of executions per second. **Comparison Options** The benchmark compares the following three options: 1. **Plain Arrow Function (`arrowFn = () => rThis;`)** 2. **Bind() from JavaScript (`bindFn = rThis.bind(this);`)** 3. **Bind() from Underscore.js library (`_bindFn = _.bind(rThis, this);`)** **Pros and Cons of Each Approach** 1. **Plain Arrow Function (`arrowFn`)**: * Pros: Easy to read and understand, no additional libraries required. * Cons: May not provide the same benefits as `bind()` when it comes to function currying or creating closures with a specific context. 2. **Bind() from JavaScript (`bindFn`)**: * Pros: Can be used to create a closure with a specific context, suitable for some use cases where `arrowFn` might not work. * Cons: May have performance overhead due to the creation of an intermediate object. 3. **Bind() from Underscore.js library (`_bindFn`)**: * Pros: Provides a similar functionality to `bind()` from JavaScript but with additional benefits, such as supporting currying and partial application. * Cons: Requires including an external library, which might have performance implications. **Underscore.js Library** The benchmark uses the Underscore.js library (`_`) for its `bind()` function. The library provides a range of utility functions, including `bind()`, which can be useful in certain scenarios. However, it also adds an additional layer of abstraction and potential performance overhead compared to using native JavaScript's `bind()` function. **No Special JS Features or Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. **Benchmark Results** The latest benchmark results show that the `_bindFn` approach provides the highest number of executions per second, followed by the `arrowFn` approach, and then the `bindFn` approach. This suggests that using the Underscore.js library's `bind()` function provides a performance advantage in this specific scenario. **Other Alternatives** If you're interested in exploring alternative approaches, you could consider: * Using native JavaScript's `Function.prototype.bind()` method instead of `_bindFn`. * Implementing a custom binding mechanism for the arrow function (`arrowFn`). * Using a different library or framework that provides optimized implementations of binding functions. Keep in mind that the choice of approach ultimately depends on the specific use case and requirements of your project.
Related benchmarks:
Arrow function vs bind function
Arrow function vs bind function dont bind
Arrow function vs bind function2021-reznik
Arrow function vs bind function creation
Comments
Confirm delete:
Do you really want to delete benchmark?