getComputedStyle vs style vs .css()

JavaScript performance comparison

Revision 2 of this test case created by l

Info

getComputedStyle vs style vs .css()

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="element" style="width:200px">My Element</div>
<script>
  var element = document.getElementById("element");
  var $element = $("#element");
</script>

Preparation code output

My Element

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
defaultView-getComputedStyle
var width0 = +document.defaultView.getComputedStyle(element, null).getPropertyValue("width");
pending…
window-getComputedStyle
var width1 = +getComputedStyle(element, null).width;
pending…
style
var width2 = +element.style.width;
pending…
.css()
var width3 = +$element.css("width");
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