diff --git a/bun.lockb b/bun.lockb index cf8f1e1..93f4dc5 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index cae0567..f080e04 100644 --- a/package.json +++ b/package.json @@ -1,50 +1,50 @@ { - "name": "bun-http-framework-benchmark", - "scripts": { - "benchmark": "bun bench.ts", - "kill-port": "kill-port 3000", - "ts-node": "ts-node" - }, - "devDependencies": { - "@hono/node-server": "^1.12.0", - "@types/bun": "^1.1.6", - "@types/express": "^4.17.21", - "@types/kill-port": "^2.0.3", - "@types/koa": "^2.15.0", - "@types/koa-bodyparser": "^4.3.12", - "@types/koa-router": "^7.4.8" - }, - "dependencies": { - "@bit-js/byte": "^1.6.1", - "@elysiajs/fn": "^0.6.1", - "@hapi/hapi": "^21.3.10", - "@nbit/bun": "^0.13.4", - "@nestjs/common": "^10.3.10", - "@nestjs/core": "^10.3.10", - "@nestjs/platform-express": "^10.3.10", - "@oakserver/oak": "^14.1.0", - "bunrest": "^1.3.8", - "elysia": "1.1.18", - "express": "^4.19.2", - "fastify": "^4.28.1", - "h3": "^1.12.0", - "hono": "^4.5.3", - "hyper-express": "^6.16.4", - "kill-port": "^2.0.1", - "koa": "^2.15.3", - "koa-bodyparser": "^4.4.1", - "koa-router": "^12.0.1", - "nhttp-land": "^1.3.26", - "reflect-metadata": "^0.2.2", - "rxjs": "^7.8.1", - "ts-node": "^10.9.2", - "typescript": "^5.5.4", - "ultimate-express": "^1.2.5", - "vixeny": "^0.1.47", - "wobe": "^1.1.7" - }, - "module": "index.ts", - "peerDependencies": { - "typescript": "^5.0.0" - } + "name": "bun-http-framework-benchmark", + "scripts": { + "benchmark": "bun bench.ts", + "kill-port": "kill-port 3000", + "ts-node": "ts-node" + }, + "devDependencies": { + "@hono/node-server": "^1.12.0", + "@types/bun": "^1.1.6", + "@types/express": "^4.17.21", + "@types/kill-port": "^2.0.3", + "@types/koa": "^2.15.0", + "@types/koa-bodyparser": "^4.3.12", + "@types/koa-router": "^7.4.8" + }, + "dependencies": { + "@elysiajs/fn": "^0.6.1", + "@hapi/hapi": "^21.3.10", + "@mapl/app": "^0.1.6", + "@nbit/bun": "^0.13.4", + "@nestjs/common": "^10.3.10", + "@nestjs/core": "^10.3.10", + "@nestjs/platform-express": "^10.3.10", + "@oakserver/oak": "^14.1.0", + "bunrest": "^1.3.8", + "elysia": "1.1.18", + "express": "^4.19.2", + "fastify": "^4.28.1", + "h3": "^1.12.0", + "hono": "^4.5.3", + "hyper-express": "^6.16.4", + "kill-port": "^2.0.1", + "koa": "^2.15.3", + "koa-bodyparser": "^4.4.1", + "koa-router": "^12.0.1", + "nhttp-land": "^1.3.26", + "reflect-metadata": "^0.2.2", + "rxjs": "^7.8.1", + "ts-node": "^10.9.2", + "typescript": "^5.5.4", + "ultimate-express": "^1.2.5", + "vixeny": "^0.1.47", + "wobe": "^1.1.7" + }, + "module": "index.ts", + "peerDependencies": { + "typescript": "^5.0.0" + } } diff --git a/src/bun/bun.ts b/src/bun/bun.ts index 640b3b5..4c9e62d 100644 --- a/src/bun/bun.ts +++ b/src/bun/bun.ts @@ -20,17 +20,16 @@ Bun.serve({ const pathIndex = url.indexOf('/', 12) + 1 const queryIndex = url.indexOf('?', pathIndex) - const path = - queryIndex === -1 - ? url.substring(pathIndex) - : url.substring(pathIndex, queryIndex) + const path = url.substring(pathIndex, queryIndex >>> 0) - if (path.length === 0) + let len = path.length; + if (len === 0) return req.method === 'GET' ? hiRes.clone() : notFound switch (path.charCodeAt(0)) { case 105: if ( + len === 3 && path.charCodeAt(1) === 100 && path.charCodeAt(2) === 47 && req.method === 'GET' @@ -42,16 +41,8 @@ Bun.serve({ const nameQueryIdx = url.indexOf('name=', queryIndex + 1) if (nameQueryIdx === -1) return notFound - const nameQueryEndIdx = url.indexOf('&', nameQueryIdx + 1) return new Response( - `${path.substring(3, queryIndex)} ${ - nameQueryEndIdx === -1 - ? url.substring(nameQueryIdx + 5) - : url.substring( - nameQueryIdx + 5, - nameQueryEndIdx - ) - }`, + `${path.substring(3, queryIndex)} ${url.substring(nameQueryIdx + 5, url.indexOf('&', nameQueryIdx + 1) >>> 0)}`, queryHeaders ) } @@ -59,7 +50,8 @@ Bun.serve({ return notFound case 106: - return path.charCodeAt(1) === 115 && + return len === 4 && + path.charCodeAt(1) === 115 && path.charCodeAt(2) === 111 && path.charCodeAt(3) === 110 && req.method === 'POST' diff --git a/src/bun/byte.ts b/src/bun/byte.ts deleted file mode 100644 index 9b1d5f7..0000000 --- a/src/bun/byte.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Byte, query, send } from '@bit-js/byte' - -const xPoweredBy = ['X-Powered-By', 'benchmark'] as [string, string] - -// Extract the 'name' parameter value from query -const getName = query.get('name') - -// Serve directly -export default new Byte() - .get('/', send.body('Hi')) - // Send ID with query - .get('/id/:id', (ctx) => { - ctx.headers.push(xPoweredBy) - return ctx.body(`${ctx.params.id} ${getName(ctx)}`) - }) - // Yield body - .post('/json', async (ctx) => ctx.json(await ctx.req.json())) diff --git a/src/bun/mapl.ts b/src/bun/mapl.ts new file mode 100644 index 0000000..39fca24 --- /dev/null +++ b/src/bun/mapl.ts @@ -0,0 +1,16 @@ +import { router, jitc } from '@mapl/app'; + +const id = router() + .headers({ 'x-powered-by': 'benchmark' }) + .get('/:id', (c) => `${c.params[0]} ${new URL(c.req.url).searchParams.get('name')}`) + +const app = router() + .build('/', () => 'Hi') + .post('/json', { + type: 'json', + fn: async (c) => c.req.json() + }) + .route('/id', id); + +export default + await jitc(app, { exposeStatic: true }); diff --git a/src/deno/mapl.ts b/src/deno/mapl.ts new file mode 100644 index 0000000..930f7eb --- /dev/null +++ b/src/deno/mapl.ts @@ -0,0 +1,17 @@ +import { router, jitc } from '@mapl/app'; + +const id = router() + .headers({ 'x-powered-by': 'benchmark' }) + .get('/:id', (c) => `${c.params[0]} ${new URL(c.req.url).searchParams.get('name')}`) + +const app = router() + .build('/', () => 'Hi') + .post('/json', { + type: 'json', + fn: async (c) => c.req.json() + }) + .route('/id', id); + +jitc(app).then((result) => { + Deno.serve({ port: 3000 }, result.fetch); +});