jQuery Cached Set
JavaScript performance comparison
Info
Compare performance of cached vs repeated element selections
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="top" class="mydiv">
<p id="para_1" class="mytext">
Paragraph one
</p>
<p id="para_2" class="mytext">
Paragraph two
</p>
<p id="para_3" class="mytext">
Paragraph three
</p>
<span id="span_1" class="mytext">
Text in a span
</span>
</div>
<p id="para_4" class="mytext">
Paragraph four
</p>
<p id="para_5" class="mytext">
Paragraph five
</p>
<p id="para_6" class="mytext">
Paragraph six
</p>
<script>
var parent_el = document.getElementById("top");
var cached = jQuery(parent_el).find('p.mytext');
</script>
Preparation code output
Paragraph one
Paragraph two
Paragraph three
Text in a spanParagraph four
Paragraph five
Paragraph six
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Cached elements |
|
pending… |
No cache |
|
pending… |
Cache2 |
|
pending… |
Cach3 |
|
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 Nilayan Sharma
- Revision 3: published
- Revision 4: published
- Revision 6: published
- Revision 7: published
0 comments