classList v old way
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div data-fixture id="a">
</div>
<div data-fixture id="b">
</div>
<script>
var a = document.getElementById("a"),
b = $("#b");
function addClasses(el, classes) {
classes = classes.split(" ")
for (var i = 0, l = classes.length; i < l; i++) {
el.classList.add(classes[i]);
}
}
</script>
<script>
Benchmark.prototype.setup = function() {
var classesNum = 50
classes = "foo0";
for (var i = 1; i < classesNum; i++) {
classes += " foo" + i;
}
};
Benchmark.prototype.teardown = function() {
$("[data-fixture]").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 | |
|---|---|---|
classList |
|
pending… |
classList wrapped |
|
pending… |
jQuery |
|
pending… |
jQuery separate |
|
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