diff --git a/benchmark-results.json b/benchmark-results.json deleted file mode 100644 index 8cb3b88e..00000000 --- a/benchmark-results.json +++ /dev/null @@ -1 +0,0 @@ -[{"name":"spirit-router","version":"0.5.0","hasRouter":true,"requests":"24275.2","latency":"40.71","throughput":"4.33"},{"name":"spirit","version":"0.6.1","requests":"24030.8","latency":"41.15","throughput":"4.29"},{"name":"bare","version":"10.13.0","requests":"23717.2","latency":"41.65","throughput":"4.23"},{"name":"polka","version":"0.5.2","hasRouter":true,"requests":"23261.6","latency":"42.48","throughput":"4.15"},{"name":"fastify","version":"4.20.0","hasRouter":true,"requests":"22878.0","latency":"43.20","throughput":"4.10"},{"name":"server-base-router","version":"7.1.32","hasRouter":true,"requests":"22188.8","latency":"44.55","throughput":"3.96"},{"name":"server-base","version":"7.1.32","requests":"21468.0","latency":"46.06","throughput":"3.83"},{"name":"connect","version":"3.7.0","requests":"21225.6","latency":"46.60","throughput":"3.79"},{"name":"yeps","version":"1.1.1","requests":"20822.4","latency":"47.52","throughput":"3.71"},{"name":"connect-router","version":"1.3.8","hasRouter":true,"requests":"20303.6","latency":"48.73","throughput":"3.62"},{"name":"polkadot","version":"1.0.0","hasRouter":false,"requests":"20205.6","latency":"48.99","throughput":"3.60"},{"name":"vapr","version":"0.6.0","hasRouter":true,"requests":"19662.9","latency":"50.34","throughput":"3.23"},{"name":"h3-router","version":"1.7.1","hasRouter":true,"requests":"19423.7","latency":"50.98","throughput":"3.19"},{"name":"koa","version":"2.14.2","requests":"18877.7","latency":"52.47","throughput":"3.37"},{"name":"yeps-router","version":"1.2.0","hasRouter":true,"requests":"18747.6","latency":"52.84","throughput":"3.34"},{"name":"take-five","version":"2.0.0","hasRouter":true,"requests":"18378.1","latency":"53.89","throughput":"6.61"},{"name":"koa-isomorphic-router","version":"1.0.1","hasRouter":true,"requests":"18290.7","latency":"54.16","throughput":"3.26"},{"name":"h3","version":"1.7.1","requests":"18159.7","latency":"54.55","throughput":"2.98"},{"name":"restify","version":"11.1.0","hasRouter":true,"requests":"17932.7","latency":"55.23","throughput":"3.23"},{"name":"koa-router","version":"12.0.0","hasRouter":true,"requests":"17062.0","latency":"58.10","throughput":"3.04"},{"name":"0http","version":"3.5.2","hasRouter":true,"requests":"16971.2","latency":"58.41","throughput":"3.03"},{"name":"restana","version":"4.9.7","hasRouter":true,"requests":"15186.0","latency":"65.34","throughput":"2.71"},{"name":"hapi","version":"21.3.2","hasRouter":true,"requests":"13940.4","latency":"71.20","throughput":"2.49"},{"name":"fastify-big-json","version":"4.20.0","hasRouter":true,"requests":"6524.9","latency":"152.67","throughput":"75.07"},{"name":"express","version":"4.18.2","hasRouter":true,"requests":"5567.4","latency":"178.76","throughput":"0.99"},{"name":"express-with-middlewares","version":"4.18.2","hasRouter":true,"requests":"4832.4","latency":"206.00","throughput":"1.80"},{"name":"foxify","version":"0.10.20","hasRouter":true,"requests":"N/A","latency":"N/A","throughput":"N/A"},{"name":"galatajs","version":"0.1.1","hasRouter":true,"requests":"N/A","latency":"N/A","throughput":"N/A"},{"name":"micro-route","version":"2.5.0","hasRouter":true,"requests":"N/A","latency":"N/A","throughput":"N/A"},{"name":"micro","version":"10.0.1","requests":"N/A","latency":"N/A","throughput":"N/A"},{"name":"microrouter","version":"3.1.3","hasRouter":true,"requests":"N/A","latency":"N/A","throughput":"N/A"},{"name":"total.js","version":"3.4.13","hasRouter":true,"requests":"N/A","latency":"N/A","throughput":"N/A"},{"name":"trpc-router","version":"10.35.0","hasRouter":true,"requests":"N/A","latency":"N/A","throughput":"N/A"}] \ No newline at end of file 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 402a72ce..b9d101d4 100755 --- a/lib/packages.js +++ b/lib/packages.js @@ -33,6 +33,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 },