Vanilla JS V Jquery Hide

JavaScript performance comparison

Revision 3 of this test case created by Ben


Proof That Jquery SUCKS!!!.. Actually just testing this

Preparation code

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

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

Comment form temporarily disabled.

Add a comment