classname vs addClassName

JavaScript performance comparison

Test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>

<div id="test">
</div>

      
<script>
Benchmark.prototype.setup = function() {
  var testDiv = $('test');

};
</script>

Preparation code output

<div id="test"> </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
classname
classes = [];
classes.push('a');
classes.push('b');
classes.push('c');
classes.push('d');
testDiv.className = classes.join(" ");
pending…
addClassName
testDiv.addClassName('a');
testDiv.addClassName('b');
testDiv.addClassName('c');
testDiv.addClassName('d');
pending…
classname (+= instead of array)
classes = "";
classes += "a";
classes += " b";
classes += " c";
classes += " d";
testDiv.className = classes;
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