getComputedStyle vs style vs .css() (v7)

Revision 7 of this benchmark created by Jonathan 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
getComputedStyle
var element = document.getElementById("element"),
    width0 = parseInt(document.defaultView.getComputedStyle(element, null).getPropertyValue("margin-right"), 10)
ready
style
var element = document.getElementById("element"),
    width1 = parseInt(element.style.marginRight, 10);
ready
.css()
var element = $("#element"),
    width2 = parseInt(element.css("margin-right"), 10);
ready

Revisions

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