Skip to content

Instantly share code, notes, and snippets.

@conartist6
Created November 26, 2022 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conartist6/11e2ba3539699147970bc41fa500e2d7 to your computer and use it in GitHub Desktop.
Save conartist6/11e2ba3539699147970bc41fa500e2d7 to your computer and use it in GitHub Desktop.
Common empties microbenchmark
console.time('new Set');
for (let i = 0; i < 1_000_000; i++) {
new Set();
}
console.timeEnd('new Set');
console.time('new Map');
for (let i = 0; i < 1_000_000; i++) {
new Map();
}
console.timeEnd('new Map');
console.time('[]');
for (let i = 0; i < 1_000_000; i++) {
[];
}
console.timeEnd('[]');
console.time('() => {}');
for (let i = 0; i < 1_000_000; i++) {
new Set();
}
console.timeEnd('() => {}');
console.time('(() => new Map)()');
for (let i = 0; i < 1_000_000; i++) {
(() => new Map())();
}
console.timeEnd('(() => new Map)()');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment