Dom R &W II

JavaScript performance comparison

Test case created

Info

Test case Reading and Writing in to the Dom

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style>
#snail {
    background: red;
    width: 10px;
    height: 30px;
}
</style>
<div id="snail"></div>
 
<script>
Benchmark.prototype.setup = function() {
    var ncycles=10;
};
</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
reading and writing in the dom
var $di = document.getElementById('snail');
for (var i = 0; i < ncycles; i++) {
    w = parseInt($di.style.margin.replace('0px 0px 0px',''));
    w = w + 10;
    $di.style.margin = "0px 0px 0px " + w + "px";
};
pending…
caching in a variable
var $di = document.getElementById('snail');
var w = 10;
for (var i = 0; i < ncycles; i++) {
      w = w+10;
      $di.style.width = "0px 0px 0px " + w + "px";
}
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