getComputedStyle vs style vs .css() (v2)

Revision 2 of this benchmark created by l on


Description

getComputedStyle vs style vs .css()

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
defaultView-getComputedStyle
var width0 = +document.defaultView.getComputedStyle(element, null).getPropertyValue("width");
ready
window-getComputedStyle
var width1 = +getComputedStyle(element, null).width;
ready
style
var width2 = +element.style.width;
ready
.css()
var width3 = +$element.css("width");
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.