Y.one('#id') vs $('#id')

JavaScript performance comparison

Revision 6 of this test case created

Info

YUI3 vs jQuery for getting an element by its selector

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js">
</script>
<div id="el">
  Some HTML element
</div>
<script>
  var el = document.getElementById('el'),
      did = 'el',
      jid = '#el',
Y;

  function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  }
YUI().use('node', function(Y) {
window.Y = Y
});
</script>
<script>
Benchmark.prototype.setup = function() {
    //el.id = did = S4();
    //jid = '#' + did;
};
</script>

Preparation code output

Some HTML element

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Y.one('#id')
Y.one(jid).get('id');
pending…
$('#id')
$(jid).attr('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:

0 comments

Add a comment