Skip to content

Instantly share code, notes, and snippets.

@gurugray
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gurugray/8740587 to your computer and use it in GitHub Desktop.
Save gurugray/8740587 to your computer and use it in GitHub Desktop.
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