qs vs jQuery (v15)

Revision 15 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://raw.github.com/gist/568b21bbea4349d59833/qs.js"></script>
<script>
var fns = {}
function Fn(s) {

if (s in fns) return fns[s]
var a = ["_"]
, t = s.split("->")

if (t.length > 1) while (t.length) {
s = t.pop()
a = t.pop().match(/\w+/g)||""
t.length && t.push("(function("+a+"){return("+s+")})")
}
return fns[s] = new Function(a, "return(" + s + ")")
}

        String.prototype.fn = function() {
return Fn(this)
}
var el_re = /([.#:])([-\w]+)/g
        function my_find(sel) {
var rules = ["_"]
, tag = sel.replace(el_re, function(_, o, s) {
rules.push( o == "." ? "(' '+_.className+' ').indexOf(' "+s+" ')>-1" : o == "#" ? "_.id=='"+s+"'" : "_."+s );
return "";
}) || "*"
, fn = rules.join("&&").fn()
, el
, els = document.getElementsByTagName(tag)
, i = 0;

while (el = els[i++]) if (fn(el)) return el;
}
</script>

<div></div>
<div id="foo"></div>
<div class="bar"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementsBy
document.getElementsByTagName("div");
document.getElementById("foo");
document.getElementsByClassName("bar");
ready
querySelectorAll
document.querySelectorAll("div");
document.querySelectorAll("#foo");
document.querySelectorAll(".bar");
ready
jQuery
$("div");
$("#foo");
$(".bar");
ready
qs
qs("div");
qs("#foo");
qs(".bar");
ready
my_find
my_find("div");
my_find("#foo");
my_find(".bar");
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.