[NodeJs] Overhead of Promise(async/await) (more serious than you think!)
Language/Javascript 2019. 5. 16. 14:15Just see following test.
Environment
- OS: 4.15.0-47-generic #50-Ubuntu SMP.
- CPU: Intel(R) Xeon(R) CPU E5-2697 v3 @ 2.60GHz
- NodeJs: 10.15.3
Normal
function f() {}
async function main() {
let tm = -Date.now();
for (let i = 0; i < 100000; i++) {
f();
}
tm += Date.now();
console.log(tm);
}
main()
$ node test.js
3
With operations
function f() {
a = [];
for (let i = 0; i < 30; i++) { a.push(i); }
}
async function main() {
let tm = -Date.now();
for (let i = 0; i < 100000; i++) {
f();
}
tm += Date.now();
console.log(tm);
}
main()
$ node test.js
27
With await
function f() {}
async function main() {
let tm = -Date.now();
for (let i = 0; i < 100000; i++) {
await f();
}
tm += Date.now();
console.log(tm);
}
main()
$ node test.js
19
With async/await
async function f() {}
async function main() {
let tm = -Date.now();
for (let i = 0; i < 100000; i++) {
await f();
}
tm += Date.now();
console.log(tm);
}
main()
$ node test.js
26
'Language > Javascript' 카테고리의 다른 글
[NodeJs] Overhead of Promise(async/await) (more serious than you think!) (0) | 2019.05.16 |
---|---|
[Jest] Sharing code and symbolic link 문제. (0) | 2018.06.26 |
[NodeJS] Kill child process executed via 'exec' and 'spawn' (0) | 2017.12.28 |
[Javascript] Generator 를 이용해서 Callback hell을 벗어나 보기.... (0) | 2017.12.28 |
[Javascript] Understanding 'Prototype' of Javascript (0) | 2017.12.28 |
[Typescript] decorator example (0) | 2017.12.28 |
댓글을 달아 주세요