<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js'></script>
<script type="text/javascript">
var jq331 = $.noConflict(true);
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.js'></script>
<script type="text/javascript">
var jq190 = $.noConflict(true);
</script>
<div id="testElement"></div>
var el = jq331("#testElement")[0];
var className = el.className;
var el = jq190("#testElement")[0];
var className = el.className;
var el = document.querySelector('#testElement');
var className = el.className;
var el = document.getElementById('testElement');
var className = el.className;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
jQuery 3.3.1 | |
jQuery 1.9.0 | |
Vanilla JS querySelector | |
Vanilla JS getElementById |
Test name | Executions per second |
---|---|
jQuery 3.3.1 | 3863421.8 Ops/sec |
jQuery 1.9.0 | 2740617.5 Ops/sec |
Vanilla JS querySelector | 2723725.2 Ops/sec |
Vanilla JS getElementById | 4047575.8 Ops/sec |
Let's break down the benchmark test and explain what each option is tested, along with their pros and cons.
The Test:
The test compares the performance of different JavaScript libraries and methods for querying HTML elements:
querySelector
method to select elements without any library.getElementById
method to select elements without any library.Options Compared:
Pros and Cons:
Library Usage (jQuery):
In the test, jQuery is used in two versions: 3.3.1 and 1.9.0. The $.noConflict(true)
method is used to reset the $
alias and avoid conflicts with other libraries.
Special JavaScript Features/Syntax (None):
The test code does not include any special JavaScript features or syntax, such as async/await, arrow functions, or Promises.
Other Alternatives:
Keep in mind that the test is focused on comparing performance between different JavaScript libraries and methods, so alternatives like Lodash or React are not directly comparable.