summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-10-15 16:44:35 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-10-16 09:37:38 -0400
commitc61a0f2f84e619a70704b59fd72cd7da863d4461 (patch)
tree275323c80a4791b311073150f1df8d98d3a8df1b /tests
parent62962e71fe244a4b0992185f2ba900ba3fd5005e (diff)
First pass at http benchmark.
Diffstat (limited to 'tests')
-rw-r--r--tests/http_bench.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/http_bench.ts b/tests/http_bench.ts
new file mode 100644
index 000000000..89d53ad1d
--- /dev/null
+++ b/tests/http_bench.ts
@@ -0,0 +1,34 @@
+// Used for benchmarking Deno's networking. See tools/http_benchmark.py
+// TODO Replace this with a real HTTP server once
+// https://github.com/denoland/deno/issues/726 is completed.
+import * as deno from "deno";
+const addr = deno.args[1] || "127.0.0.1:4500";
+const listener = deno.listen("tcp", addr);
+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.eof) {
+ break;
+ }
+ await conn.write(response);
+ }
+ } finally {
+ conn.close();
+ }
+}
+
+async function main(): Promise<void> {
+ console.log("Listening on", addr);
+ while (true) {
+ const conn = await listener.accept();
+ handle(conn);
+ }
+}
+
+main();