Last active
October 16, 2021 15:19
-
-
Save emayom/e9c03ce1e5898aae2a5eba545087b2bf to your computer and use it in GitHub Desktop.
sync vs async
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
//동기 방식으로 작동하는 코드 | |
function loop() { | |
//for문을 실행하기 전 | |
const start = Date.now(); | |
//i가 9999999가 될 때 까지 ++ | |
for (let i = 0; i <= 9999999; i++) {} | |
const end = Date.now(); | |
//걸린 시간 => ms | |
console.log(`1번째 작업 완료! (${end - start}ms)`); | |
} | |
loop(); | |
console.log('2번째 작업 완료!'); | |
//output | |
//1번째 작업 완료! | |
//2번째 작업 완료! |
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
//비동기 방식으로 작동하는 코드 | |
function loop() { | |
setTimeout(() => { | |
//for문을 실행하기 전 | |
const start = Date.now(); | |
//i가 9999999가 될 때 까지 ++ | |
for (let i = 0; i <= 9999999; i++) {} | |
const end = Date.now(); | |
//걸린 시간 => ms | |
console.log(`1번째 작업 완료!(${end - start}ms)`); | |
},0); | |
} | |
loop(); | |
console.log('2번째 작업 완료!'); | |
//output | |
//2번째 작업 완료! | |
//1번째 작업 완료! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment