mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
31f32ed8c4
All benchmarks are done in Rust and can be invoked with `cargo bench`. Currently this has it's own "harness" that behaves like `./tools/benchmark.py` did. Because of this tests inside `cli/bench` are currently not run. This should be switched to the language provided harness once the `#[bench]` attribute has been stabilized.
29 lines
835 B
TypeScript
29 lines
835 B
TypeScript
// Used for benchmarking Deno's networking.
|
|
// TODO Replace this with a real HTTP server once
|
|
// https://github.com/denoland/deno/issues/726 is completed.
|
|
// Note: this is a keep-alive server.
|
|
const addr = Deno.args[0] || "127.0.0.1:4500";
|
|
const [hostname, port] = addr.split(":");
|
|
const listener = Deno.listen({ hostname, port: Number(port) });
|
|
const response = new TextEncoder().encode(
|
|
"HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n",
|
|
);
|
|
async function handle(conn: Deno.Conn): Promise<void> {
|
|
const buffer = new Uint8Array(1024);
|
|
try {
|
|
while (true) {
|
|
const r = await conn.read(buffer);
|
|
if (r === null) {
|
|
break;
|
|
}
|
|
await conn.write(response);
|
|
}
|
|
} finally {
|
|
conn.close();
|
|
}
|
|
}
|
|
|
|
console.log("Listening on", addr);
|
|
for await (const conn of listener) {
|
|
handle(conn);
|
|
}
|