Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Vanilla JS VS Jquery | Click Event Speed
(version: 0)
Comparing performance of: Vanilla vs Jquery
Comparing performance of:
Vanilla vs jQuery
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <div class="rte faq-list-content pb-24"> <ul> <li> <h2 class="p1">frequently asked question maybe a little longer than one row ?</h2> <p class="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Bibendum est ultricies integer quis. Iaculis urna id volutpat lacus laoreet. Mauris vitae ultricies leo integer malesuada.<br><br>Testing </p> </li> <li> <h2 class="p1">frequently asked question maybe a little longer than one row ?</h2> <p class="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Bibendum est ultricies integer quis. Iaculis urna id volutpat lacus laoreet. Mauris vitae ultricies leo integer malesuada.</p> </li> <li> <h2 class="p1">frequently asked question maybe a little longer than one row ?</h2> <p class="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Bibendum est ultricies integer quis. Iaculis urna id volutpat lacus laoreet. Mauris vitae ultricies leo integer malesuada.</p> </li> </ul> </div>
Tests:
Vanilla
window.onload =()=>{ document.querySelectorAll('.faq-list-content li h2').forEach((button) => { button.addEventListener('click', (e) => { e.preventDefault(); console.log(e.currentTarget.parentElement.classList.toggle("active")); }); }); }
jQuery
$(document).on('click', '.faq-list-content li h2', function (event) { event.preventDefault(); this.parentElement.classList.toggle("active"); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Vanilla
jQuery
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Vanilla
1162729.5 Ops/sec
jQuery
303457.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! The provided JSON represents a benchmark test on MeasureThat.net, where two approaches are compared: Vanilla JavaScript and jQuery. **What is being tested?** The benchmark tests the performance difference between using Vanilla JavaScript to attach an event listener to HTML elements versus using jQuery. Specifically, it measures how long it takes for both approaches to execute a certain amount of code when a click event occurs on a specific set of HTML elements. **Options compared:** 1. **Vanilla JavaScript**: This approach uses the `addEventListener` method and a callback function to attach an event listener to the HTML elements. 2. **jQuery**: This approach uses jQuery's `on` method and a closure to attach an event listener to the HTML elements. **Pros and Cons of each approach:** 1. **Vanilla JavaScript**: * Pros: + More flexible and customizable + Can be more efficient for large-scale applications + No dependency on jQuery library * Cons: + Requires manual management of event listeners + May require more code and complexity 2. **jQuery**: * Pros: + Simplifies event handling and attaching listeners + Reduces boilerplate code + Provides a robust set of utility functions * Cons: + Adds an extra dependency on the jQuery library + May introduce performance overhead due to the library's complexity **Library used:** In this benchmark, jQuery is used as the event handling framework. Specifically, it uses the `on` method and a closure to attach an event listener to the HTML elements. **Special JS feature or syntax:** None are mentioned in the provided benchmark definition or test cases. **Other alternatives:** If you're looking for alternative approaches to event handling, consider: 1. **Event delegation**: This technique involves attaching a single event listener to a parent element and then using event bubbling to handle clicks on child elements. 2. **Pico.js**: A lightweight event handling library that provides a simpler alternative to jQuery. 3. **Lodash**: A utility library that includes a set of functions for event handling, including `on` and `off`. Keep in mind that each approach has its trade-offs, and the best choice depends on your specific use case, performance requirements, and personal preference. I hope this explanation helps you understand what's being tested in this benchmark!
Related benchmarks:
jQuery vs Vanilla JS GetID Speed Test3
Vanilla JS VS Jquery | rem
addEventListener() vs jQuery.on() with mouseEnter
addEventListener() vs jQuery.on() with click
Comments
Confirm delete:
Do you really want to delete benchmark?