Last active
July 1, 2021 09:48
-
-
Save noseratio/2773950f88138fef329a20a077fcacc6 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
void async function() { | |
"use strict"; | |
// extending Promise | |
class PromiseEx extends Promise { | |
} | |
const iterations = 500_000; | |
const cached = Promise.resolve(); | |
// testing new Promise directly | |
console.time("new Promise"); | |
for (let n = 0; n < iterations; n++) { | |
let resolve; | |
const p = new Promise(r => resolve = r); | |
cached.then(resolve); | |
await p; | |
} | |
console.timeEnd("new Promise"); | |
// testing new PromiseEx | |
console.time("new PromiseEx"); | |
for (let n = 0; n < iterations; n++) { | |
let resolve; | |
const p = new PromiseEx(r => resolve = r); | |
cached.then(resolve); | |
await p; | |
} | |
console.timeEnd("new PromiseEx"); | |
}().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment