getComputedStyle vs style vs .css() (v23)

Revision 23 of this benchmark created by jerry 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");

  var cs = null;
  var getCStyle = function(node)
  {
    cs = cs || window.getComputedStyle(node, null);
    return cs;
  };
</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
.width()
var width4 = +$element.width();
ready
window-getComputedStyle2
var width5 = +getComputedStyle(element, null)["width"];
ready
window-getComputedStyle3
var width6 = +getCStyle(element, null)["width"];
ready

Revisions

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