Vanilla JS V Jquery Hide

JavaScript performance comparison

Revision 3 of this test case created by Ben

Info

Proof That Jquery SUCKS!!!.. Actually just testing this http://forum.yola.com/yola/topics/whyjqueryisbetterthanregularjavascript

Preparation code

<div id="Stupid_Div">
  Stupid Crap
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Preparation code output

Stupid Crap

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Jquery
$('#Stupid_Div').hide().show().hide();
pending…
Vanilla JS
document.getElementById("Stupid_Div").style.display = "none";
document.getElementById("Stupid_Div").style.display = "block";
document.getElementById("Stupid_Div").style.display = "none";
pending…
Vanilla JS Retarded Suggestion
var hide = "none"; //this var isnt needed
var show = "block"; //this var isnt needed
document.getElementById("Stupid_Div").style.display = hide;
document.getElementById("Stupid_Div").style.display = show;
document.getElementById("Stupid_Div").style.display = hide;
pending…
Vanilla JS Cache-Everything Option
var hide = "none",
show = "block",
elem = document.getElementById("Stupid_Div");
elem.style.display = hide;
elem.style.display = show;
elem.style.display = 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:

1 comment

Ben (revision owner) commented :

This is both unfair and a little stupid.

jQuery selectors are returned as collection objects with a multitude of prototyped functions attached to them. Of course this is going to be more expensive than vanilla JS. It's also going to be a hell of a lot more powerful in the event that you're going to be doing more than simply hiding or showing a DOM element - especially if the selector is cached as a var.

What you're doing here is equivalent to comparing Cambrian organisms of different genera and accusing the vertebrates of being too bony.

(I've added a "cache everything" option to rebut the so-called "retarded suggestion".)

Add a comment