ID vs Classes

JavaScript performance comparison

Test case created

Preparation code

<input id="one" class="select">
<input id="two" class="select">
<input id="three" class="select">
<input id="four" class="select">
<input id="five" class="select">
<input id="six" class="select">
<input id="seven" class="select">
<input id="eight" class="select">
<input id="nine" class="select">
<input id="ten" class="select">

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
GetEleById
document.getElementById('one').disabled = true;
document.getElementById('two').disabled = true;
document.getElementById('three').disabled = true;
document.getElementById('four').disabled = true;
document.getElementById('five').disabled = true;
document.getElementById('six').disabled = true;
document.getElementById('seven').disabled = true;
document.getElementById('eight').disabled = true;
document.getElementById('nine').disabled = true;
document.getElementById('ten').disabled = true;
pending…
QSA id
var es = ['one','two','three','four','five','six','seven','eight','nine','ten'];
for(var i=0,l=es.length;i<l;i++) {
document.getElementById(es[i]).disabled = true;
}
pending…

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

Compare results of other browsers

0 comments

Add a comment