<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<h2>Test onglets secondaire N3 </h2>
<ul class="nav nav-tabs onglets-secondaires">
<li class="active" role="presentation">
<a id="onglets-onglets-secondaire-n3" href="#content-tabsec-3" data-toggle="tab" aria-selected="true" aria-expanded="true" aria-controls="content-tabsec-3" role="tab"> [Onglet - 1] </a>
</li>
<li role="presentation">
<a id="tabsec-4" href="#content-tabsec-4" data-toggle="tab" aria-controls="content-tabsec-4" role="tab"> [Onglet - 2] </a>
</li>
<li role="presentation">
<a id="onglets-onglets-secondaire-n3-data" href="#content-tabsec-4" data-mw-onglet-secondaire-nom="Onglet 3 - DATA" data-toggle="tab" aria-controls="content-tabsec-5" role="tab"> [Onglet - 3 avec data] </a>
</li>
</ul>
</body>
</html>
$("[class='nav nav-tabs onglets-secondaires']");
$('.nav.nav-tabs.onglets-secondaires li');
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
class | |
. |
Test name | Executions per second |
---|---|
class | 369958.6 Ops/sec |
. | 357525.5 Ops/sec |
Let's break down the provided benchmark and explain what's being tested, the different approaches compared, their pros and cons, and other considerations.
Benchmark Overview
The provided benchmark is for measuring the speed of filtering classes in jQuery. The benchmark uses two different methods to achieve this:
"$([class='nav nav-tabs onglets-secondaires']");
".nav.nav-tabs.onglets-secondaires li";
Library and Purpose
The library being used is jQuery, which is a popular JavaScript library for DOM manipulation and event handling.
In this benchmark, jQuery is used to filter elements based on their class attributes. The class
method in jQuery returns an array of matched elements that have the specified class.
Approach 1: Dollar Sign Prefix
This approach uses the $
symbol to prefix the class selector. This is a common convention in jQuery for accessing DOM elements using a selector.
Pros:
Cons:
Approach 2: Dot Operator
This approach uses the dot (.) operator to access the class attribute directly.
Pros:
Cons:
Other Considerations
When comparing these two approaches, we need to consider factors such as performance, maintainability, and readability.
In general, using the $
symbol prefix can make the code more readable and easier to understand, but it may come at a slight cost in terms of performance. The dot operator approach can be faster, but it requires more manual attention to detail and consistency in its usage.
Alternatives
If you need to benchmark other class selection methods or approaches, here are some alternatives:
document.querySelector()
instead of $()
_class='nav nav-tabs onglets-secondaires'
)document.getElementsByClassName()