<div id="test1" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test2" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test3" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test4" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test5" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test6" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test7" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test8" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test9" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<div id="test10" data-sel-panel>
<div>
<h3></h3>
<div>
<label></label>
<select></select>
</div>
</div>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js'></script>
$("#test1");
$("#test1 data-sel-panel");
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Find by id | |
Find by id and attribute |
Test name | Executions per second |
---|---|
Find by id | 2484315.0 Ops/sec |
Find by id and attribute | 135981.2 Ops/sec |
Let's break down what's being tested in this benchmark.
Benchmark Overview
The benchmark compares the performance of two approaches to find elements on a webpage using jQuery: finding an element by its id
attribute and finding an element by both its id
attribute and another attribute (data-sel-panel
).
Options Being Compared
There are two options being compared:
$()
function to select an element by its id
attribute.$()
function, but with an additional argument (data-sel-panel
) that specifies a CSS selector to match.Pros and Cons of Each Approach
id
alone, as it allows for more precise matching.Library Used
In this benchmark, jQuery is used as the library. Its $()
function is a crucial part of the test, as it provides a convenient way to select elements on the webpage.
Special JavaScript Feature or Syntax
There doesn't seem to be any special JavaScript feature or syntax being tested in this benchmark.
Other Considerations
The benchmark is using a real-world browser (Firefox 79) and a desktop platform (Windows) to simulate a typical user experience. The test cases are designed to cover both common use cases: finding an element by its id
attribute and finding an element by both its id
attribute and another attribute.
Alternative Approaches
Other approaches to find elements on a webpage could include:
document.getElementById()
method: This is a native JavaScript function that can be used to select an element by its id
attribute.Overall, this benchmark provides a useful comparison of two common approaches to find elements on a webpage using jQuery, highlighting the trade-offs between simplicity, efficiency, and flexibility.