YUI v3.4.1 vs. jQuery v1.7.4 DOM queries
JavaScript performance comparison
Preparation code
<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js">
</script>
<script src="http://code.jquery.com/jquery-1.7.min.js">
</script>
<div id="test">
<div class="testlink">
<a href="#" id="linkone" title="test">test link</a>
</div>
<div class="testmenu">
<ul>
<li class="menuitem itemone">
<a href="#" title="item 1">menu item 1</a>
</li>
<li class="menuitem itemtwo">
<a href="#" title="item 2">menu item 2</a>
</li>
<li class="menuitem itemthree">
not clickable item 3
</li>
</ul>
</div>
</div>
<script>
var selectors = ['body', 'div', 'body div', 'div a', 'div > a', 'div[class^=test]', 'div, li, a', '.menuitem', 'li.menuitem', '#linkone', 'div#test', 'a[title*=item]', 'a[title=test]', 'li:nth-child(even)', 'li:nth-child(odd)', 'li:last-child', 'li:first-child'];
var Y_Instance = YUI();
Y_Instance.use('node');
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
jQuery v1.7 |
|
pending… |
YUI v3.4.1 |
|
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 Jesse Cravens
- Revision 2: published by Jesse Cravens
- Revision 3: published by Jesse Cravens
- Revision 5: published
- Revision 6: published by Mauno
- Revision 7: published by Jamie Pratt
- Revision 8: published
- Revision 11: published by Mauno
- Revision 13: published by Christoph
- Revision 15: published by Christoph
- Revision 16: published by Christoph
- Revision 18: published by Christoph
- Revision 20: published
- Revision 21: published by Mickey Mart
- Revision 22: published
- Revision 23: published by westworld
- Revision 24: published by CTPAx
- Revision 25: published by Kevin
- Revision 26: published
- Revision 27: published
- Revision 28: published by CTPAX
- Revision 29: published
- Revision 30: published by Kevin
- Revision 31: published by thantoldo
- Revision 32: published
- Revision 33: published by opalfroot
- Revision 34: published by KDO
- Revision 36: published
- Revision 37: published by SavvaP
- Revision 40: published by Andrew
- Revision 41: published
- Revision 42: published
- Revision 44: published by vivek
- Revision 45: published
- Revision 46: published
- Revision 47: published by YUI-fix
- Revision 48: published
- Revision 49: published
1 comment
Hey, found this as part of a Moodle discussion. This (prior to Revision 32) is a TERRIBLE test. The YUI object instantiation and use() call are far and away the most expensive part of any YUI execution block, since it includes config parsing, dependency calculation, and library loading; of COURSE executing them over and over will take more time.
Creating a single instance of YUI will save a chunk of time and should be standard practice for anyone building a modular site of serious size; consolidating use() blocks drops the time much further. There can be a serious conversation about selector times based on that, but including YUI().use(...) as part of your repeated execution block is just going to create a legitimate comparison.