DOM vs innerHTML
JavaScript performance comparison
Preparation code
<div id='sample'>
<h1 id='title'>Title</h1>
<h2 id='subtitle'>by</h2>
<div id='content'>
</div>
</div>
<script>
Benchmark.prototype.setup = function() {
var colors = ["red", "yellow", "green", "cyan", "blue", "magenta"];
};
Benchmark.prototype.teardown = function() {
var sample = document.getElementById('sample');
sample.innerHTML = "<h1 id='title'>Title</h1><h2 id='subtitle'>by</h2><div id='content'></div>";
};
</script>
Preparation code output
Title
by
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
DOM |
|
pending… |
innerHTML |
|
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:
- Revision 1: published by gonchuki
- Revision 6: published by Arthur Schreiber
- Revision 9: published by gonchuki
- Revision 10: published by gonchuki
- Revision 11: published by LouisChen
- Revision 15: published by Thomas Aylott
- Revision 16: published by Thomas Aylott
- Revision 17: published by Andrew Jackson
- Revision 18: published by matt g.
- Revision 20: published
- Revision 21: published by Eamon Nerbonne
- Revision 24: published
- Revision 25: published
- Revision 26: published
- Revision 27: published
- Revision 28: published
- Revision 29: published
- Revision 30: published
0 comments