getComputedStyle vs style vs .css()

JavaScript performance comparison

Test case created by Mircea Piturca

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>

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
getComputedStyle
var element = document.getElementById("element"),
    width0 = parseInt(document.defaultView.getComputedStyle(element, null).getPropertyValue("width"), 10)
pending…
style
var element = document.getElementById("element"),
    width1 = parseInt(element.style.width, 10);
pending…
.css()
var element = $("#element"),
    width2 = parseInt(element.css("width"), 10);
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