classname vs addClassName

JavaScript performance comparison

Test case created

Preparation code

<script src="//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

Test runner

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

Java applet disabled.

Testing in unknown unknown
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

Add a comment