Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
jQuery vs pure JS : html
(version: 4)
innerHTML vs html
Comparing performance of:
jQuery vs pure JS
Created:
9 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
Script Preparation code:
var frag = document.createDocumentFragment(); for (var i=0; i<100; i++){ var inDiv = document.createElement('span'); inDiv.id="s_"+i; inDiv.innerHTML = 'bla'; inDiv.className = 'myclass'; frag.appendChild(inDiv); } document.body.appendChild(frag);
Tests:
jQuery
$('span.myclass').each(function () { $(this).html('x'); });
pure JS
$('span.myclass').each(function () { this.innerHTML = 'y'; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
jQuery
pure JS
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0
Browser/OS:
Chrome 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
jQuery
5552.1 Ops/sec
pure JS
11488.6 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 compares two approaches to update the `innerHTML` property of HTML elements: 1. **jQuery**: The first test case uses jQuery's `$` function to iterate over all `<span>` elements with a class name of "myclass" and update their `innerHTML` property to 'x'. 2. **Pure JS**: The second test case updates the `innerHTML` property directly using the `this` keyword, without any additional library. **Options Compared:** The benchmark compares two options: * Using jQuery's `$` function to iterate over elements * Updating the `innerHTML` property directly using pure JavaScript syntax **Pros and Cons of each approach:** * **jQuery**: + Pros: - Easier to read and maintain, especially for complex DOM manipulations. - Provides a convenient way to access and manipulate the DOM. + Cons: - Adds an extra library dependency, which may introduce overhead or security risks if not managed properly. - Can be slower than pure JavaScript approaches due to the overhead of the jQuery library. * **Pure JS**: + Pros: - Faster execution, as it avoids the overhead of the jQuery library. - More control over the DOM manipulation process, allowing for fine-grained optimization. + Cons: - Can be more error-prone and less readable for complex DOM manipulations. **Library:** The benchmark uses jQuery 1.12.4, which is a widely used JavaScript library for DOM manipulation and event handling. **Special JS Feature/Syntax:** There is no special JavaScript feature or syntax being tested in this benchmark. The focus is on comparing the performance of using jQuery versus pure JavaScript to update `innerHTML` properties. **Other Alternatives:** If you want to explore alternative approaches, here are a few options: * **Vanilla JavaScript**: You can use vanilla JavaScript functions like `forEach`, `map`, or `reduce` to iterate over elements and update their `innerHTML` property. * **React or Virtual DOM libraries**: If you're building complex web applications with React or another virtual DOM library, you may want to explore how these libraries handle DOM updates and performance optimization. Keep in mind that the benchmark is focused on comparing the performance of using jQuery versus pure JavaScript, so these alternative approaches might not be directly relevant.
Related benchmarks:
createTextNode vs innerHTML vs innerText
JS: append vs appendChild
JS: insertBefore vs appendChild
jquery text vs js innerHtml
createTextNode vs textContent vs innerText vs append vs innerHTML vs insertAdjacentHTMLvs replaceChildren vs appendChild
Comments
Confirm delete:
Do you really want to delete benchmark?