jQuery vs. Prototype vs. _j (v30)

Revision 30 of this benchmark created on


Description

This is a comparison of selector engine speed between jQuery 2.0.3 and Prototype 1.6.1 and _j 0.4

Curious to see how _j performs

Preparation HTML

<!doctype html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/prototype/1.6.1/prototype.js">
</script>
<script src="//code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="http://lzacorp.com/_jv0.4/_j.min.js"></script>
<script>
$.noConflict();
jQuery.fn.thisEach = function(fn){//fastEach
var t = jQuery([0]), l = this.length, i = -1, e;
while(
++i < l
&& (e = t[0] = this[i])
&& fn.call(t, i, e) !== false
)
return this;
};
</script>


</head>
<body>
<ul id="list">
<li>
<ul class="sublist">
<li>
item1
</li>
<li>
item2
</li>
</ul>
</li>
<li>
<ul class="sublist">
<li>
item1
</li>
<li>
item2
</li>
</ul>
</li><li>
<ul class="sublist">
<li>
item1
</li>
<li>
item2
</li>
</ul>
</li><li>
<ul class="sublist">
<li>
item1
</li>
<li>
item2
</li>
</ul>
</li>
</ul>
</body>
</html>

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype
$$("#list .sublist li").each(function(item) {
    $(item).addClassName( 'cssclass' ).removeClassName( 'cssclass' )
});
ready
jquery
jQuery("#list .sublist li").addClass( 'cssclass' ).removeClass( 'cssclass' );
ready
_j
_jSel("#list .sublist li").forEach(function(item){
_jAddClass(item, "cssclass");
_jDelClass(item, "cssclass");
});
ready
jQuery with fastEach
jQuery("#list .sublist li").thisEach(function(item){
this.addClass( 'cssclass' ).removeClass( 'cssclass' );
});
ready

Revisions

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