classList v old way
JavaScript performance comparison
Preparation code
<script src="http://code.jquery.com/jquery-git2.js">
</script>
<script src="http://code.jquery.com/jquery-git2.js">
</script>
<script>
$j = jQuery.noConflict();
</script>
<script src="https://raw.github.com/mzgol/jquery.classList/master/jquery.class_list.js">
</script>
<div id="a">
</div>
<script>
Benchmark.prototype.setup = function() {
var a1 = $("#a"),
a2 = $j("#a");
var fooOdd = "foo43";
var fooQuarter = "foo40";
var classes = "foo0";
var classesEven = "foo0";
var classesQuarter = "foo0";
var classesNum = 100;
for (var i = 1; i < classesNum; i++) {
classes += " foo" + i;
if (i % 2 === 0) {
classesEven += " foo" + i;
}
if (i % 4 === 0) {
classesQuarter += " foo" + i;
}
}
a1.get(0).className = classesEven;
};
Benchmark.prototype.teardown = function() {
$("#a").attr("class", "");
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
addClass: many, className |
|
pending… |
addClass: many, classList |
|
pending… |
removeClass: many, className |
|
pending… |
removeClass: many, classList |
|
pending… |
toggleClass: many, className |
|
pending… |
toggleClass: many, classList |
|
pending… |
hasClass: className |
|
pending… |
hasClass: classList |
|
pending… |
addClass: single, className |
|
pending… |
addClass: single, classList |
|
pending… |
removeClass: single, className |
|
pending… |
removeClass: single, classList |
|
pending… |
toggleClass: single, className |
|
pending… |
toggleClass: single, classList |
|
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:
- Revision 1: published by Rick Waldron
- Revision 2: published
- Revision 3: published by Dave Dopson
- Revision 4: published by m_gol
- Revision 5: published by m_gol
- Revision 6: published
- Revision 7: published by m_gol
- Revision 8: published by m_gol
- Revision 9: published
- Revision 10: published by m_gol
0 comments