Last active
February 20, 2021 11:50
-
-
Save JaeYeopHan/00267315d534aa7488d611a0cc413b55 to your computer and use it in GitHub Desktop.
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
let elemA = document.getElementsByTagName('a'); | |
let body = document.getElementsByTagName('body')[0]; | |
console.log('[한번에 appendChild 해주는 경우 with fragment]') | |
console.time('testDocumentFragment'); | |
fragment = document.createDocumentFragment(); | |
for(var i = 0; i < elemA.length * 100; i++){ | |
var span = document.createElement('span'); | |
span.textContent = 'element1'; | |
fragment.appendChild(span); | |
} | |
body.appendChild(fragment); | |
console.timeEnd('testDocumentFragment'); | |
// ===================================== | |
console.log('[매번 appendChild 해주는 경우]') | |
console.time('testCreateElemEach'); | |
var base = document.createElement('span'); | |
for(var i = 0; i < elemA.length * 100; i++){ | |
var span = document.createElement('span'); | |
span.textContent = 'element2'; | |
base.appendChild(span); | |
} | |
body.appendChild(base); | |
console.timeEnd('testCreateElemEach'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment