YUI.all('div.cl') selector vs YUI.all('.cl')

JavaScript performance comparison

Revision 17 of this test case created by Rajesh Taneja

Info

Fastest way get a YUI3 object of a DOM element of which I have the class

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 class="el">
  Some HTML element
</div>
<div class="el">
  Some HTML element
  <div class="el">
      Some HTML element
  </div>
</div>
<div class="el">
  Some HTML element
</div>
<script>
  var divc = 'div.el',
      c = '.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() {
   
   
};
</script>

Preparation code output

Some HTML element
Some HTML element
Some HTML element
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.all('div.cl')
Y.all(divc);
pending…
Y.all('.cl');
Y.all(c);
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