comparison benchmark/bun-http-framework-benchmark/src/deno/deno.ts @ 183:a8976a008a9d

[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
author MrJuneJune <me@mrjunejune.com>
date Fri, 23 Jan 2026 21:19:08 -0800
parents
children
comparison
equal deleted inserted replaced
179:8d17f6e6e290 183:a8976a008a9d
1 // @ts-nocheck
2 const jsonHeaders = { headers: [['Content-Type', 'application/json']] },
3 queryHeaders = { headers: [['X-Powered-By', 'benchmark']] },
4 notFound = new Response(null, { status: 404 }),
5 hiRes = new Response('Hi')
6
7 function toResponse(json: unknown) {
8 return new Response(JSON.stringify(json), jsonHeaders)
9 }
10
11 // json -> [106, 115, 111, 110]
12 // id/ -> [105, 100, 47]
13 // Simulate the maximum performance you can get with Bun.serve
14 // We should appreciate how frameworks make all these stuff easier :) - Reve
15 Deno.serve({ port: 3000 }, (req) => {
16 const url = req.url
17
18 const pathIndex = url.indexOf('/', 12) + 1
19 const queryIndex = url.indexOf('?', pathIndex)
20 const path =
21 queryIndex === -1
22 ? url.substring(pathIndex)
23 : url.substring(pathIndex, queryIndex)
24
25 if (path.length === 0)
26 return req.method === 'GET' ? hiRes.clone() : notFound
27
28 switch (path.charCodeAt(0)) {
29 case 105:
30 if (
31 path.charCodeAt(1) === 100 &&
32 path.charCodeAt(2) === 47 &&
33 req.method === 'GET'
34 ) {
35 // Shouldn't include a slash and should have query
36 if (queryIndex === -1 || path.indexOf('/', 3) !== -1)
37 return notFound
38
39 const nameQueryIdx = url.indexOf('name=', queryIndex + 1)
40 if (nameQueryIdx === -1) return notFound
41
42 const nameQueryEndIdx = url.indexOf('&', nameQueryIdx + 1)
43 return new Response(
44 `${path.substring(3, queryIndex)} ${
45 nameQueryEndIdx === -1
46 ? url.substring(nameQueryIdx + 5)
47 : url.substring(nameQueryIdx + 5, nameQueryEndIdx)
48 }`,
49 queryHeaders
50 )
51 }
52
53 return notFound
54
55 case 106:
56 return path.charCodeAt(1) === 115 &&
57 path.charCodeAt(2) === 111 &&
58 path.charCodeAt(3) === 110 &&
59 req.method === 'POST'
60 ? req.json().then(toResponse)
61 : notFound
62
63 default:
64 return notFound
65 }
66 })