CSS Style - Case 2

JavaScript performance comparison

Test case created by Cong Liu

Preparation code

<div id="foo">
  Bar
</div>
<style>
  .my-style { background-color: red; width: 200px; }
</style>
<script>
Benchmark.prototype.setup = function() {
    var foo = document.getElementById('foo');
};

Benchmark.prototype.teardown = function() {
    foo.style.cssText = foo.className = '';
};
</script>

Preparation code output

Bar

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
foo.style.*
foo.style.backgroundColor = 'red';
foo.style.width = '200px';
pending…
foo.style.cssText
foo.style.cssText = 'background-color: red; width: 200px;';
pending…
foo.className
foo.className = 'my-style';
pending…
foo.classList
foo.classList.add('my-style');
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:

0 comments

Add a comment