innerHTML vs DOM methods
JavaScript performance comparison
Info
See comments @ http://stackoverflow.com/questions/7099258
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ol id="list">
</ol>
<script>
var html = "";
for (i = 0; i <= 2000; i++) {
html += "<li><a href='#'>Hi</a></li>";
}
var fragment = document.createDocumentFragment();
var list = document.getlementById("list");
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
innerHTML |
|
pending… |
DOM methods |
|
pending… |
Document Fragment |
|
pending… |
Document Fragment, no jQuery |
|
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 nwellcome
- Revision 2: published by Matt Ball
- Revision 3: published by nwellcome
- Revision 4: published
- Revision 5: published
0 comments