change css in many ways

JavaScript performance comparison

Revision 3 of this test case created by tamlyn

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="id">
</div>
<script>
Benchmark.prototype.setup = function() {
    var left = 10,
        top = 10,
        el = document.getElementById('id'),
    $el = $(el),
        styl;
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
style.x
el.style.left = left + "px";
el.style.top  = top  + "px";
pending…
cached style.x
styl = el.style;

styl.left = left + "px";
styl.top = top + "px";
pending…
cssText
el.style.cssText = "left: " + left + "px; top: " + top + "px;";
pending…
$.css
$el.css({
  left: left,
  top: top
});
pending…
setAttribute
el.setAttribute("style", "left: " + left + "px; top: " + top + "px;");
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