Data lookup vs Style lookup

JavaScript performance comparison

Test case created by Drew Wells

Info

Sometimes you need to do a lot of style lookups. Can you see benefits from caching results in data.

Preparation code

<span style="display: block; " data-touched="false">
  Virgin
</span>
<script>
Benchmark.prototype.setup = function() {
    var span = document.getElementsByTagName('span')[0];
};
</script>

Preparation code output

Virgin

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Style lookup inline
span.style.display;
pending…
Style lookup inherited
span.style.hidden;
pending…
Data lookup valid
span.dataset.touched;
pending…
Data lookup getAttribute
span.getAttribute('data-touched');
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