<div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div>
<div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div>
<a id="parent" >
<div><div><div></div><div><div><div></div><div><div><div>
<span id="child">Need span</span>
<div></div></div></div></div></div></div></div><div></div></div>
<svg class="icon md-16 icon-shevron-right text-muted"></svg>
</a>
<div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div><div><div><div></div><div><div><div></div><div><div><div>
<span>pew</span>
<div></div></div></div></div></div></div></div><div></div></div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js'></script>
var $element = $("#parent");
$element.find("#child");
$("#child", $element);
$("#child");
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
find with "find" | |
find with selector and scope | |
find with selector |
Test name | Executions per second |
---|---|
find with "find" | 3962206.8 Ops/sec |
find with selector and scope | 3047806.8 Ops/sec |
find with selector | 10125758.0 Ops/sec |
I'll explain what's being tested in the provided JSON.
The benchmark is testing three different ways to select an element on a web page using jQuery:
$element
variable, which refers to the parent container). The benchmark compares the performance of this method.#child
, which targets an element with the ID child
.$element
variable as part of the scope, like so: $("#child", $element)
. This allows the search to occur within a specific context (in this case, the $element
variable).Now, let's discuss the pros and cons of each approach:
In this benchmark, the test cases are:
The latest benchmark results show that the scoped selector notation performs the best (faster), followed by the selector notation, and then the find() method. This is likely due to the optimized implementation of the scoped selector notation in jQuery.
As for other details, the benchmark is run on a Chrome 102 browser on a Windows desktop with a high number of executions per second (around 1.5 million).