jQuery .css() vs. MooTools .setStyles() vs. DOM .style

JavaScript performance comparison

Revision 2 of this test case created

Info

Testing for jQuery .css(), MooTools .setStyles() and native DOM element.style performance, as well as element.style.cssText.

Preparation code

<script src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
<div id="test">Hello! World</div>
<script>
Benchmark.prototype.setup = function() {
    var element = document.getElementById("test");
    var $element = $(element); // avoid overhead on jQuery object wrapping
   
};

Benchmark.prototype.teardown = function() {
    document.getElementById("test").removeAttribute("style");
};
</script>

Preparation code output

Hello! World

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery .css()
$element.css("height", "320px");
pending…
element.style
element.style.height = "320px";
 
pending…
element.style.cssText=
element.style.cssText = "height: 320px;";
 
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