jQuery animate vs css

JavaScript performance comparison

Test case created

Info

Test, how much slower jQuery animate is in comparison of setting the width with css

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style type="text/css">#test{width:0px;display:inline;height:50px;}</style>
<div id="test">

</div>
<script>
Benchmark.prototype.setup = function() {
    var percent = 100, i=0, step = 10, $div = $("#test");
   
};
</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
jQuery animate
while(i < percent){
i += step;
$div.animate({'width' : i});
}
pending…
jQuery css width
while(i < percent){
i += step;
$div.css({'width' : i});
}
pending…
jQuery css width as key-value
while(i < percent){
i += step;
$div.animate('width' , i);
}
pending…

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

Compare results of other browsers

0 comments

Add a comment