ClassList versus ClassName

JavaScript performance comparison

Revision 19 of this test case created by Luke Bonaccorsi

Preparation code

<div id="foo"></div>
<script>fooEl = document.getElementById('foo');</script>

      
<script>
Benchmark.prototype.setup = function() {
  fooEl.className = ' aaaa bbbb cccc dddd '; 
  //note the leading and trailing spaces

};
</script>

Preparation code output

<div id="foo"></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
remove with contains
if(fooEl.classList.contains('zzzz')){
    fooEl.classList.remove('zzzz');
}
pending…

Revisions

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

0 Comments