Last active
May 29, 2016 04:36
-
-
Save nishinoshake/c1d374ed240d100edf70 to your computer and use it in GitHub Desktop.
javascriptの時間測定
This file contains hidden or 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
//DOM生成を単純に繰り返すと3000ms | |
console.time('createNode'); | |
for (var i = 0; i < 100000; i++) { | |
$('#Main').append('<div>' + i + '</div>'); | |
} | |
console.timeEnd('createNode'); | |
//キャッシュすると300ms | |
var dom = ''; | |
for (var i = 0; i < 100000; i++) { | |
dom += '<div>' + i + '</div>'; | |
} | |
$('#Main').append(dom); |
This file contains hidden or 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
var $span = $('<span>'); | |
// eachはforの倍以上かかる | |
$span.each(function() { | |
$(this).text($(this).text()+1); | |
}); | |
for ( i = 0, length = $span.length; i < length; i++ ) { | |
$span.eq(i).text($span.eq(i).text()+1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment