Mercurial
diff benchmark/bun-http-framework-benchmark/src/node/uws.js @ 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmark/bun-http-framework-benchmark/src/node/uws.js Fri Jan 23 21:19:08 2026 -0800 @@ -0,0 +1,61 @@ +/* Non-SSL is simply App() */ +const uWS = require('uWebSockets.js') + +uWS.App() + .get( + '/', + new uWS.DeclarativeResponse() + .writeHeader('content-type', 'text/plain') + .end('Hi') + ) + .get( + '/id/:id', + new uWS.DeclarativeResponse() + .writeHeader('content-type', 'text/plain') + .writeHeader('x-powered-by', 'benchmark') + .writeParameterValue('id') + .write(' ') + .writeQueryValue('name') + .end() + ) + .post('/json', (res, req) => { + readJson( + res, + (obj) => { + res.writeHeader('content-type', 'application/json').end( + JSON.stringify(obj) + ) + }, + () => { + res.end('Ok') + } + ) + }) + .listen(3000, (listenSocket) => { + if (listenSocket) { + console.log('Listening to port 3000') + } + }) + +function readJson(res, cb, err) { + let buffer + + res.onData((ab, isLast) => { + let chunk = Buffer.from(ab) + if (isLast) { + if (buffer) { + cb(JSON.parse(Buffer.concat([buffer, chunk]))) + } else { + cb(JSON.parse(chunk)) + } + } else { + if (buffer) { + buffer = Buffer.concat([buffer, chunk]) + } else { + buffer = Buffer.concat([chunk]) + } + } + }) + + res.onAborted(err) +}