Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Bun implementation, add Mapl and remove Byte #84

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
96 changes: 48 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
22 changes: 7 additions & 15 deletions src/bun/bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -42,24 +41,17 @@ 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
)
}

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'
Expand Down
17 changes: 0 additions & 17 deletions src/bun/byte.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/bun/mapl.ts
Original file line number Diff line number Diff line change
@@ -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 });
17 changes: 17 additions & 0 deletions src/deno/mapl.ts
Original file line number Diff line number Diff line change
@@ -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);
});