Last active
August 29, 2015 13:55
-
-
Save gurugray/8740587 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
var handlers = []; | |
//исскуственная функция сна | |
function sleep(millis) { | |
var date = new Date(), | |
curDate = null; | |
do { curDate = new Date(); } while(curDate-date < millis); | |
} | |
//создаём функцию хендлер | |
function fabric(i) { | |
return function(){ | |
sleep(15); | |
} | |
} | |
//генерируем 1000 функций | |
for (var i = 0; i < 1000; i++) { | |
handlers.push(fabric()); | |
} | |
console.time('sync'); | |
handlers.forEach(function(handler){ | |
handler(); | |
}); | |
console.timeEnd('sync'); | |
console.time('async'); | |
handlers.forEach(function(handler){ | |
setTimeout(handler, 10); | |
}); | |
console.timeEnd('async'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment