diff --git a/benchmarks/tinyhttp.mjs b/benchmarks/tinyhttp.mjs new file mode 100644 index 00000000..7af88293 --- /dev/null +++ b/benchmarks/tinyhttp.mjs @@ -0,0 +1,9 @@ +import { App } from '@tinyhttp/app' + +const app = new App() + +app.get('/', (_, res) => { + res.send('Hello World!') +}) + +app.listen(3000) diff --git a/lib/autocannon.js b/lib/autocannon.js index 05fe7f16..2f8d6d64 100644 --- a/lib/autocannon.js +++ b/lib/autocannon.js @@ -5,10 +5,12 @@ import { writeFile as _writeFile, mkdir as _mkdir, access as _access } from 'fs' import compare from 'autocannon-compare' import { join } from 'path' import { promisify } from 'util' +import { createRequire } from 'module' const writeFile = promisify(_writeFile) const mkdir = promisify(_mkdir) const access = promisify(_access) +const require = createRequire(import.meta.url) const resultsDirectory = join(process.cwd(), 'results') diff --git a/lib/bench.js b/lib/bench.js index 167b1f58..a103cffd 100644 --- a/lib/bench.js +++ b/lib/bench.js @@ -1,6 +1,7 @@ #!/usr/bin/env node 'use strict' +import { access } from 'node:fs/promises' import { fork } from 'child_process' import ora from 'ora' import { join } from 'path' @@ -12,7 +13,14 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url)) const doBench = async (opts, handler) => { const spinner = ora(`Started ${handler}`).start() - const forked = fork(join(__dirname, '..', 'benchmarks', handler + '.cjs')) + let forked + try { + await access(join(__dirname, '..', 'benchmarks', handler + '.cjs')) + forked = fork(join(__dirname, '..', 'benchmarks', handler + '.cjs')) + } catch { + forked = fork(join(__dirname, '..', 'benchmarks', handler + '.mjs')) + } + try { spinner.color = 'magenta' spinner.text = `Warming ${handler}` diff --git a/lib/packages.js b/lib/packages.js index f4b1f82e..d165fdd0 100755 --- a/lib/packages.js +++ b/lib/packages.js @@ -34,6 +34,7 @@ const packages = { spirit: { extra: true }, 'spirit-router': { extra: true, hasRouter: true }, 'take-five': { hasRouter: true }, + tinyhttp: { package: '@tinyhttp/app' }, 'total.js': { hasRouter: true }, 'trpc-router': { extra: true, hasRouter: true, package: '@trpc/server' }, vapr: { hasRouter: true },