Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 179:8d17f6e6e290 | 183:a8976a008a9d |
|---|---|
| 1 /* Non-SSL is simply App() */ | |
| 2 const uWS = require('uWebSockets.js') | |
| 3 | |
| 4 uWS.App() | |
| 5 .get( | |
| 6 '/', | |
| 7 new uWS.DeclarativeResponse() | |
| 8 .writeHeader('content-type', 'text/plain') | |
| 9 .end('Hi') | |
| 10 ) | |
| 11 .get( | |
| 12 '/id/:id', | |
| 13 new uWS.DeclarativeResponse() | |
| 14 .writeHeader('content-type', 'text/plain') | |
| 15 .writeHeader('x-powered-by', 'benchmark') | |
| 16 .writeParameterValue('id') | |
| 17 .write(' ') | |
| 18 .writeQueryValue('name') | |
| 19 .end() | |
| 20 ) | |
| 21 .post('/json', (res, req) => { | |
| 22 readJson( | |
| 23 res, | |
| 24 (obj) => { | |
| 25 res.writeHeader('content-type', 'application/json').end( | |
| 26 JSON.stringify(obj) | |
| 27 ) | |
| 28 }, | |
| 29 () => { | |
| 30 res.end('Ok') | |
| 31 } | |
| 32 ) | |
| 33 }) | |
| 34 .listen(3000, (listenSocket) => { | |
| 35 if (listenSocket) { | |
| 36 console.log('Listening to port 3000') | |
| 37 } | |
| 38 }) | |
| 39 | |
| 40 function readJson(res, cb, err) { | |
| 41 let buffer | |
| 42 | |
| 43 res.onData((ab, isLast) => { | |
| 44 let chunk = Buffer.from(ab) | |
| 45 if (isLast) { | |
| 46 if (buffer) { | |
| 47 cb(JSON.parse(Buffer.concat([buffer, chunk]))) | |
| 48 } else { | |
| 49 cb(JSON.parse(chunk)) | |
| 50 } | |
| 51 } else { | |
| 52 if (buffer) { | |
| 53 buffer = Buffer.concat([buffer, chunk]) | |
| 54 } else { | |
| 55 buffer = Buffer.concat([chunk]) | |
| 56 } | |
| 57 } | |
| 58 }) | |
| 59 | |
| 60 res.onAborted(err) | |
| 61 } |