Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
AddEventListener
(version: 0)
Comparing performance of:
addEvenListener vs .on
Created:
9 years ago
by:
Guest
Jump to the latest result
Tests:
addEvenListener
for (i=0; i<10000;i++) { document.addEventListener('click', ()=>{}) }
.on
for (i=0; i<10000;i++) { $('document').on('click', function(){})}
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
addEvenListener
.on
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand what's being tested in the provided benchmark. **What is being tested?** The benchmark tests two approaches for attaching an event listener to the `document` object: `addEventListener()` and `.on()` (also known as jQuery's "on" method). The test case creates a loop that runs 10,000 times, adding an event listener with no callback function. **Options compared** There are two options being compared: 1. **`addEventListener()`**: This is the native JavaScript method for attaching an event listener to an element or document. It takes three arguments: the type of event, the target element, and a callback function. 2. **`.on()` (jQuery's "on" method)**: This is a part of the jQuery library, which is a popular JavaScript library for DOM manipulation and event handling. The `.on()` method also takes three arguments: the type of event, the selector or target element, and a callback function. **Pros and Cons** **`addEventListener()`**: Pros: * Native JavaScript method, widely supported by modern browsers. * More efficient than using jQuery's `.on()` method. * Allows for more fine-grained control over event listeners. Cons: * May require additional setup, such as creating a new function object to serve as the callback. **`.on()` (jQuery's "on" method)**: Pros: * Simple and intuitive syntax. * Works with jQuery's event handling system. * Can be useful for chaining multiple events together. Cons: * Not native JavaScript, which may lead to compatibility issues with some browsers or libraries. * Less efficient than using `addEventListener()`. * May pollute the global namespace if not used carefully. **Other considerations** When choosing between these two approaches, consider the following factors: * **Browser support**: If you need to support older browsers that don't have native `addEventListener()` support, `.on()` might be a safer choice. * **Performance**: If performance is critical, using `addEventListener()` will likely be faster than using `.on()`. * **Library usage**: If you're already using jQuery, `.on()` might be a more convenient choice. Otherwise, `addEventListener()` is generally the better option. **Library usage** The test case uses jQuery's `.on()` method, which suggests that the author wants to compare its performance with native JavaScript's `addEventListener()` method. **Special JS feature or syntax** There are no special features or syntaxes being tested in this benchmark. Both approaches use standard JavaScript and jQuery methods. I hope this explanation helps you understand what's being tested in the provided benchmark!
Related benchmarks:
AddEventListener
addEventListener() vs jQuery.on() with click
_performance_comparison: DeepClone vs removing/adding eventlisteners
Cost of adding and removing events
Comments
Confirm delete:
Do you really want to delete benchmark?