Ract-style DOM updates

JavaScript performance comparison

Test case created by Joshua Piccari

Info

Testing out the theories behind React.js. Will batch updates on a DOM tree be faster than replacing the entire DOM tree à la .innerHTML or similar?

Preparation code

<div id="test-dom-root">
        <h1>
                Testing the Theories of <a class="react" href="http://facebook.github.io/react/">React</a>
        </h1>
        <p>
                How will the wholesale swap of the DOM tree fair against the powerful <a class="vd" href="http://google.com/search?q=react+virtual+dom">virtual DOM</a>.
        </p>
</div>
<script>
Benchmark.prototype.setup = function() {
    var tree = document.querySelector('#test-dom-root'),
        anchors = tree.querySelectorAll('a'),
        randomId = Math.round(Math.random() * 1000);
};
</script>

Preparation code output

Testing the Theories of React

How will the wholesale swap of the DOM tree fair against the powerful virtual DOM.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
.innerHTML
tree.innerHTML = '<h1>Testing the Theories of <a data-random-id="' + randomId + '" href="http://facebook.github.io/react/">react article</a></h1><p>How will the wholesale swap of the DOM tree fair against the powerful <a data-random-id="' + randomId + '" href="http://google.com/search?q=react+virtual+dom">virtual dom google earch</a>.</p>';
pending…
Batch updates
anchors[0].setAttribute('data-random-id', randomId);
anchors[0].textContent = 'react article';
anchors[1].setAttribute('data-random-id', randomId);
anchors[1].textContent = 'virtual dom google earch';
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