Last active
December 22, 2015 10:59
-
-
Save pikotea/6462456 to your computer and use it in GitHub Desktop.
innerHTMLのスピードテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// firefox: | |
// test1a -> 18.83772399999998 | |
// test1b -> 12.661566999999877 | |
// test1c -> 0.32783100000006016 | |
// chrome: | |
// test1a -> 53.948999993735924 | |
// test1b -> 28.740999987348914 | |
// test1c -> 0.7929999846965075 | |
// 準備 | |
var data = []; | |
for ( var i = 1; i <= 100; i++ ) { | |
data.push('アイテム' + i); | |
} | |
// 毎回全入れ替え+innerHTML毎回参照 | |
function test1a() { | |
var ul = document.querySelector('#output'); | |
for ( var i = 0, len = data.length; i < len; i++ ) { | |
ul.innerHTML += '<li><p>' + data[i] + '</p></li>'; | |
} | |
} | |
// 毎回全入れ替えするけど、innerHTML参照1回 | |
function test1b() { | |
var ul = document.querySelector('#output'), | |
html = ul.innerHTML; | |
for ( var i = 0, len = data.length; i < len; i++ ) { | |
html += '<li>' + data[i] + '</li>'; | |
ul.innerHTML = html; | |
} | |
} | |
// 1回だけ全入れ替え | |
function test1c() { | |
var ul = document.querySelector('#output'), | |
html = ''; | |
for ( var i = 0, len = data.length; i < len; i++ ) { | |
html += '<li>' + data[i] + '</li>'; | |
} | |
ul.innerHTML = html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment