innerHTML vs createElement() and appendChild()
JavaScript performance comparison
Info
Compares the performance of adding elements to DOM by using strings and innerHTML and creating DOMElement objects and appending them with appendChild().
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
innerHTML |
|
pending… |
createElement() and appendChild() |
|
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 GarciaWebDev
- Revision 2: published by GarciaWebDev
- Revision 3: published by jbdemonte
- Revision 4: published by Ian White
- Revision 5: published and last updated
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 12: published
- Revision 13: published by Ben Rolfe
- Revision 14: published
1 comment
This test is biased. It forces the rendering engine to reconstruct the DOM for the entire body tag on each iteration when using innerHTML (hint: body.innerHTML += ...). That is a problem because the contents of the body tag are increasing with each iteration. On the other hand, the manual construction using appendChild only touches one node in each iteration. Do not get fooled by these results.