Vanilla JS V Jquery Hide

JavaScript performance comparison

Revision 3 of this test case created by Ben

Preparation code

<div id="Stupid_Div">
  Stupid Crap
<script src="">

Preparation code output

<div id="Stupid_Div"> Stupid Crap </div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Vanilla JS
document.getElementById("Stupid_Div").style.display = "none";
document.getElementById("Stupid_Div").style.display = "block";
document.getElementById("Stupid_Div").style.display = "none";
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;
Vanilla JS Cache-Everything Option
var hide = "none",
show = "block",
elem = document.getElementById("Stupid_Div"); = hide; = show; = hide;

Compare results of other browsers


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


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".)

aa commented :

mt1125 mt1125

Stupid Crap