Skip to content

Commit

Permalink
add benchmark for net/http
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Dec 6, 2018
1 parent 6cc89b9 commit e2053be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tools/http_benchmark.py
Expand Up @@ -16,6 +16,12 @@ def deno_http_benchmark(deno_exe):
return run(deno_cmd)


def deno_net_http_benchmark(deno_exe):
deno_cmd = [deno_exe, "--allow-net", "tools/net_http_bench.ts", ADDR]
print "http_benchmark testing DENO using net/http."
return run(deno_cmd)


def node_http_benchmark():
node_cmd = ["node", "tools/node_http.js", ADDR.split(":")[1]]
print "http_benchmark testing NODE."
Expand All @@ -38,6 +44,7 @@ def http_benchmark(deno_exe, hyper_hello_exe):
r = {}
# TODO Rename to "deno_tcp"
r["deno"] = deno_http_benchmark(deno_exe)
r["deno_net_http"] = deno_net_http_benchmark(deno_exe)
r["node"] = node_http_benchmark()
r["node_tcp"] = node_tcp_benchmark()
r["hyper"] = hyper_http_benchmark(hyper_hello_exe)
Expand Down
15 changes: 15 additions & 0 deletions tools/net_http_bench.ts
@@ -0,0 +1,15 @@
import * as deno from "deno";
import { serve } from "https://deno.land/x/net/http.ts";

const addr = deno.args[1] || "127.0.0.1:4500";
const server = serve(addr);

const body = new TextEncoder().encode("Hello World");

async function main(): Promise<void> {
for await (const request of server) {
await request.respond({ status: 200, body });
}
}

main();

0 comments on commit e2053be

Please sign in to comment.