getComputedStyle vs style vs .css() (v10)

Revision 10 of this benchmark created by David 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>

Test runner

Ready to run.

Testing in
TestOps/sec
jq css {width}
var element = $("#element"),
    width = parseInt(element.css("width"));
ready
js .width()
var element = $("#element"),
    width = element.width()
ready
style
var element = document.getElementById("element"),
    width = parseInt(element.style.width);
ready
getComputedStyle
var element = document.getElementById("element"),
    width = parseInt(getComputedStyle(element).width);
ready

Revisions

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