change css in many ways

JavaScript performance comparison

Revision 6 of this test case created

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'),
      styl;
    this.c = $(el).css;
};
</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…
shortcut to $ function
this.c('left', left);
this.c('top', top);
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:

1 comment

James commented :

Anyone had a look at how it's implemented within jQuery? it's only more JS not magic... I will have a look but bit busy with work.

Add a comment