Created
November 16, 2021 04:27
-
-
Save hanayashiki/f1d8c3fdf5c51b3e51853a8a768b97ac to your computer and use it in GitHub Desktop.
module resolution benchmarks
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
import { build } from 'esbuild' | |
import typescript from '@rollup/plugin-typescript' | |
export async function esbuildResolve(id, dir) { | |
let result | |
await build({ | |
stdin: { | |
contents: `import ${JSON.stringify(id)}`, | |
resolveDir: dir, | |
}, | |
write: false, | |
bundle: true, | |
treeShaking: false, | |
ignoreAnnotations: true, | |
platform: 'node', | |
plugins: [{ | |
name: 'resolve', | |
setup({ onLoad }) { | |
onLoad({ filter: /.*/ }, (args) => { | |
result = args.path | |
return { contents: '' } | |
}) | |
}, | |
}], | |
}) | |
return result | |
} | |
(async () => { | |
let ops = 0 | |
let time = Date.now() | |
while (true) { | |
await esbuildResolve('./dummy', '.') | |
ops++ | |
if (Date.now() - time > 1000) { | |
break; | |
} | |
} | |
console.log('esbuildResolve:', ops, '/sec') | |
ops = 0 | |
time = Date.now() | |
const ts = typescript(); | |
while (true) { | |
ts.resolveId('./dummy', '/Users/chenyuwang/esno/esbuild-node-loader/dummy.ts') | |
if (Date.now() - time > 1000) { | |
break; | |
} | |
ops++ | |
} | |
console.log('typescript resolveId (cached):', ops, '/sec') | |
ops = 0 | |
time = Date.now() | |
while (true) { | |
const ts = typescript({}); | |
ts.resolveId('./dummy', '/Users/chenyuwang/esno/esbuild-node-loader/dummy.ts') | |
if (Date.now() - time > 1000) { | |
break; | |
} | |
ops++ | |
} | |
console.log('typescript resolveId (not-cached):', ops, '/sec') | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment