Skip to content

Instantly share code, notes, and snippets.

@noseratio
Last active July 1, 2021 09:48
Show Gist options
  • Save noseratio/2773950f88138fef329a20a077fcacc6 to your computer and use it in GitHub Desktop.
Save noseratio/2773950f88138fef329a20a077fcacc6 to your computer and use it in GitHub Desktop.
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