<form id="data">
<input name="field1"/>
<input name="field2"/>
<input name="field3"/>
<input name="field4"/>
<input name="field5"/>
<input name="field6"/>
<input name="field7"/>
<input name="field8"/>
<input name="field9"/>
<input name="field10"/>
</form>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js'></script>
var $element = $("#data");
$element.find("input[name='field5']");
$element.find("*[name='field5']");
$element.find("[name='field5']");
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
find by tag and name attribute | |
find by wildcard and name attribute | |
find by name attribute |
Test name | Executions per second |
---|---|
find by tag and name attribute | 64600.6 Ops/sec |
find by wildcard and name attribute | 63187.1 Ops/sec |
find by name attribute | 63231.9 Ops/sec |
What is being tested?
The provided benchmark tests the performance of different approaches for finding an element in a HTML document using jQuery. The approaches are:
name
attribute, which uses the [name='fieldX']
syntax.name
attribute and then selecting one, which uses the *[name='fieldX']
syntax (using a wildcard).input
) and then filtering by name
attribute.Options compared
The benchmark compares the performance of these three approaches:
[name='fieldX']
name
attribute.*[name='fieldX']
input[name='fieldX']
name
attribute.Other considerations
The benchmark also considers other factors, such as:
Library and its purpose
In this benchmark, jQuery is used as a library to provide the find
method for selecting elements in the HTML document.
Special JS feature or syntax
There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is on the performance of different approachess to achieve a specific goal (finding an element by its name
attribute).
Alternatives
Other approaches for finding an element in a HTML document using jQuery might include:
document.getElementById('id')
instead of find
querySelectorAll
or querySelector
methods from the DOM APIKeep in mind that these alternatives may have different performance characteristics, depending on the specific use case and requirements.