diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-07-01 12:59:01 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-01 12:59:01 +0530 |
commit | 350994e6a66ed78b0fa38c1ffad4928297ffd9b3 (patch) | |
tree | bf00b1c2323d5fb85b07b2a16d861e76561eedc3 | |
parent | a27acbc2ec63dd684cf57990b30d757cd0477d9b (diff) |
chore(cli/bench): Add more HTTP benchmarks (#14995)
-rw-r--r-- | cli/bench/http.rs | 3 | ||||
-rw-r--r-- | cli/bench/http/deno_http_read_headers.js | 17 | ||||
-rw-r--r-- | cli/bench/http/deno_http_read_headers.lua | 5 | ||||
-rw-r--r-- | cli/bench/http/deno_post_json.js | 19 | ||||
-rw-r--r-- | cli/bench/http/deno_post_json.lua | 3 | ||||
-rw-r--r-- | cli/bench/http/node_http_read_headers.js | 10 | ||||
-rw-r--r-- | cli/bench/http/node_http_read_headers.lua | 5 | ||||
-rw-r--r-- | cli/bench/http/node_post_json.js | 18 | ||||
-rw-r--r-- | cli/bench/http/node_post_json.lua | 3 |
9 files changed, 83 insertions, 0 deletions
diff --git a/cli/bench/http.rs b/cli/bench/http.rs index c577e577a..0af2b5393 100644 --- a/cli/bench/http.rs +++ b/cli/bench/http.rs @@ -31,6 +31,9 @@ pub fn benchmark( let entry = entry?; let pathbuf = entry.path(); let path = pathbuf.to_str().unwrap(); + if path.ends_with(".lua") { + continue; + } let name = entry.file_name().into_string().unwrap(); let file_stem = pathbuf.file_stem().unwrap().to_str().unwrap(); diff --git a/cli/bench/http/deno_http_read_headers.js b/cli/bench/http/deno_http_read_headers.js new file mode 100644 index 000000000..75346b38d --- /dev/null +++ b/cli/bench/http/deno_http_read_headers.js @@ -0,0 +1,17 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + +const addr = Deno.args[0] || "127.0.0.1:4500"; +const [hostname, port] = addr.split(":"); +const listener = Deno.listen({ hostname, port: Number(port) }); +console.log("Server listening on", addr); + +for await (const conn of listener) { + (async () => { + const requests = Deno.serveHttp(conn); + for await (const { respondWith, request } of requests) { + const bar = request.headers.get("foo"); + respondWith(new Response(bar)) + .catch((e) => console.log(e)); + } + })(); +} diff --git a/cli/bench/http/deno_http_read_headers.lua b/cli/bench/http/deno_http_read_headers.lua new file mode 100644 index 000000000..64f1923ff --- /dev/null +++ b/cli/bench/http/deno_http_read_headers.lua @@ -0,0 +1,5 @@ +wrk.headers["foo"] = "bar" +wrk.headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" +wrk.headers["Viewport-Width"] = "1920" +wrk.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" +wrk.headers["Accept-Language"] = "en,la;q=0.9"
\ No newline at end of file diff --git a/cli/bench/http/deno_post_json.js b/cli/bench/http/deno_post_json.js new file mode 100644 index 000000000..90c68f6e4 --- /dev/null +++ b/cli/bench/http/deno_post_json.js @@ -0,0 +1,19 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + +const addr = Deno.args[0] || "127.0.0.1:4500"; +const [hostname, port] = addr.split(":"); +const listener = Deno.listen({ hostname, port: Number(port) }); +console.log("Server listening on", addr); + +for await (const conn of listener) { + (async () => { + const requests = Deno.serveHttp(conn); + for await (const { respondWith, request } of requests) { + if (request.method == "POST") { + const json = await request.json(); + respondWith(new Response(json.hello)) + .catch((e) => console.log(e)); + } + } + })(); +} diff --git a/cli/bench/http/deno_post_json.lua b/cli/bench/http/deno_post_json.lua new file mode 100644 index 000000000..cc6c4e226 --- /dev/null +++ b/cli/bench/http/deno_post_json.lua @@ -0,0 +1,3 @@ +wrk.method = "POST" +wrk.headers["Content-Type"] = "application/json" +wrk.body = '{"hello":"deno"}'
\ No newline at end of file diff --git a/cli/bench/http/node_http_read_headers.js b/cli/bench/http/node_http_read_headers.js new file mode 100644 index 000000000..98716c72b --- /dev/null +++ b/cli/bench/http/node_http_read_headers.js @@ -0,0 +1,10 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +const http = require("http"); +const port = process.argv[2] || "4544"; +console.log("port", port); +http + .Server((req, res) => { + const bar = req.headers["foo"]; + res.end(bar); + }) + .listen(port); diff --git a/cli/bench/http/node_http_read_headers.lua b/cli/bench/http/node_http_read_headers.lua new file mode 100644 index 000000000..64f1923ff --- /dev/null +++ b/cli/bench/http/node_http_read_headers.lua @@ -0,0 +1,5 @@ +wrk.headers["foo"] = "bar" +wrk.headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" +wrk.headers["Viewport-Width"] = "1920" +wrk.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" +wrk.headers["Accept-Language"] = "en,la;q=0.9"
\ No newline at end of file diff --git a/cli/bench/http/node_post_json.js b/cli/bench/http/node_post_json.js new file mode 100644 index 000000000..074d005d0 --- /dev/null +++ b/cli/bench/http/node_post_json.js @@ -0,0 +1,18 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +const http = require("http"); +const port = process.argv[2] || "4544"; +console.log("port", port); +http + .Server((req, res) => { + if (req.method == "POST") { + let body = ""; + req.on("data", function (data) { + body += data; + }); + req.on("end", function () { + const { hello } = JSON.parse(body); + res.end(hello); + }); + } + }) + .listen(port); diff --git a/cli/bench/http/node_post_json.lua b/cli/bench/http/node_post_json.lua new file mode 100644 index 000000000..71697a068 --- /dev/null +++ b/cli/bench/http/node_post_json.lua @@ -0,0 +1,3 @@ +wrk.method = "POST" +wrk.headers["Content-Type"] = "application/json" +wrk.body = '{"hello":"node"}'
\ No newline at end of file |