Native/QuerySelector VS jQuery
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div>
<div id="foo">
<div class="bar"></div>
</div>
</div>
<script>
function select(selector, element)
{
element = element || document;
selector = selector.replace(/(^\s|\s$)/, "");
if (selector.indexOf(",") > 0)
{
var selectors = selector.split(",");
for (var index = 0; index < selectors.length; index++)
{
selectors[index] = select(selectors[index]);
}
return selectors;
}
else if (selector.length < 1)
{
return null;
}
else
{
if (selector.charAt(0) == "#")
{
return element.getElementById(selector.substring(1));
}
else if (selector.charAt(0) == ".")
{
return element.getElementsByClassName(selector.substring(1));
}
else
{
return element.getElementsByTagName(selector);
}
}
}
</script>
<div id="baz"></div>
<div class="bar"></div>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Native |
|
pending… |
querySelector |
|
pending… |
jQuery |
|
pending… |
Selector IMP |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published
- Revision 4: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 12: published
- Revision 14: published
- Revision 15: published
0 comments