Just 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' 카테고리의 다른 글
[Javascript] Performance: Add large number of array elements to set. (0) | 2020.09.10 |
---|---|
[rxjs] Interesting unexpected behavior of withLatestFrom() at Rxjs. (0) | 2020.04.14 |
[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 |