Last active
May 7, 2022 03:29
-
-
Save EtherDream/52649e4939008e149d0cb3a944c055b7 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
(function() { | |
'use strict' | |
async function pending() { | |
return 11 | |
} | |
function mayPending() { | |
if (Math.random() < 0.001) { | |
return pending() | |
} | |
return 22 | |
} | |
async function main() { | |
console.time('s1') | |
for (let i = 0; i < 1e6; i++) { | |
const val = await mayPending() | |
} | |
console.timeEnd('s1') | |
console.time('s2') | |
for (let i = 0; i < 1e6; i++) { | |
const ret = mayPending() | |
const val = ret.then ? await ret : ret | |
} | |
console.timeEnd('s2') | |
} | |
main() | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
s1: 2412.416015625 ms
s2: 20.87890625 ms