various js libraries+native selector shootout

JavaScript performance comparison

Test case created

Info

Hide 10 nodes.

Preparation code

<script src="//cdn.jqmobi.com/1.2/jq.mobi.min.js"></script>
<script src="//yui.yahooapis.com/3.8.1/build/yui/yui-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/zepto/1.0rc1/zepto.min.js"></script>

<div id="sidebar">
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
 <span class="foo">Foo</span>
</div>
<div id="list">
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
 <span class="bar">Bar</span>
</div>
<div id="details">
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
 <span class="baz">Baz</span>
</div>
 
<script>
Benchmark.prototype.setup = function() {
    yQuery = YUI().use('node');
    qQuery = jq;
    zQuery = Zepto;
};
</script>

Preparation code output

Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar
Baz Baz Baz Baz Baz Baz Baz Baz Baz Baz

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
querySelectorAll("#details > span"), length countdown
var nodes = document.querySelectorAll("#details > span");
for (var i = nodes.length; i--;) {
  nodes[i].style.display = "none";
}
pending…
querySelectorAll("#details > span"), cache length
var nodes = document.querySelectorAll("#details > span");
for (var i = 0, len = nodes.length; i < len; i++) {
  nodes[i].style.display = "none";
}
pending…
querySelectorAll("#details > span")
var nodes = document.querySelectorAll("#details > span");
for (var i = 0; i < nodes.length; i++) {
  nodes[i].style.display = "none";
}
pending…
querySelectorAll(".baz"), length countdown
var nodes = document.querySelectorAll(".baz");
for (var i = nodes.length; i--;) {
  nodes[i].style.display = "none";
}
pending…
querySelectorAll(".baz"), cache length
var nodes = document.querySelectorAll(".baz");
for (var i = 0, len = nodes.length; i < len; i++) {
  nodes[i].style.display = "none";
}
pending…
querySelectorAll(".baz")
var nodes = document.querySelectorAll(".baz");
for (var i = 0; i < nodes.length; i++) {
  nodes[i].style.display = "none";
}
pending…
document.getElementById("details").getElementsByTagName("span"), length countdown
var nodes = document.getElementById("details").getElementsByTagName("span");
for (var i = nodes.length; i--;) {
  nodes[i].style.display = "none";
}
pending…
document.getElementById("details").getElementsByTagName("span"), cache length
var nodes = document.getElementById("details").getElementsByTagName("span");
for (var i = 0, len = nodes.length; i < len; i++) {
  nodes[i].style.display = "none";
}
pending…
document.getElementById("details").getElementsByTagName("span")
var nodes = document.getElementById("details").getElementsByTagName("span");
for (var i = 0; i < nodes.length; i++) {
  nodes[i].style.display = "none";
}
pending…
document.getElementsByClassName("baz"), length countdown
var nodes = document.getElementsByClassName("baz");
for (var i = nodes.length; i--;) {
  nodes[i].style.display = "none";
}
pending…
document.getElementsByClassName("baz"), cache length
var nodes = document.getElementsByClassName("baz");
for (var i = 0, len = nodes.length; i < len; i++) {
  nodes[i].style.display = "none";
}
pending…
document.getElementsByClassName("baz")
var nodes = document.getElementsByClassName("baz");
for (var i = 0; i < nodes.length; i++) {
  nodes[i].style.display = "none";
}
pending…
zepto("#details > span")
zQuery("#details > span").hide();
pending…
zepto(".baz")
zQuery(".baz").hide();
pending…
jquery("#details > span")
jQuery("#details > span").hide();
pending…
jquery(".baz")
jQuery(".baz").hide();
pending…
YUI("#details > span")
yQuery.all("#details > span").hide();
pending…
YUI(".baz")
yQuery.all(".baz").hide();
pending…
jq.mobi("#details > span")
qQuery("#details > span").hide();
pending…
jq.mobi(".baz")
qQuery(".baz").hide();
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