Effect of narrowing by id on Sizzle (jQuery) efficiency
JavaScript performance comparison
Info
See http://stackoverflow.com/questions/1229259/jquery-pitfalls-to-avoid/1229405#1229405
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<div id="parent">
<div class="a">
a
</div>
<div class="a">
a
</div>
<div class="a">
a
</div>
<div class="a">
a
</div>
<div class="a">
a
</div>
<div class="a">
a
</div>
<div class="a">
a
</div>
<div class="a">
a
</div>
<div class="a">
a
</div>
</div>
<script>
var doc = document;
function loop(ele) {
for (var i = ele.length; i--;) {
$(ele[i]).css({
border: '1px solid pink'
});
}
};
</script>
Preparation code output
a
a
a
a
a
a
a
a
a
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Class only |
|
pending… |
Class and id |
|
pending… |
querySelectorAll w/ id |
|
pending… |
querySelector w/o id |
|
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 by Gergő Tisza
- Revision 2: published
- Revision 3: published by Kristof Neirynck
- Revision 4: published by BrianH
- Revision 5: published
0 comments