diff --git a/cli/bench/http.rs b/cli/bench/http.rs index c577e577a2..0af2b5393a 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 0000000000..75346b38df --- /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 0000000000..64f1923ff3 --- /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 0000000000..90c68f6e45 --- /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 0000000000..cc6c4e226d --- /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 0000000000..98716c72b3 --- /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 0000000000..64f1923ff3 --- /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 0000000000..074d005d05 --- /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 0000000000..71697a0682 --- /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