mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
chore(cli/bench): Add more HTTP benchmarks (#14995)
This commit is contained in:
parent
a27acbc2ec
commit
350994e6a6
9 changed files with 83 additions and 0 deletions
|
@ -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();
|
||||
|
||||
|
|
17
cli/bench/http/deno_http_read_headers.js
Normal file
17
cli/bench/http/deno_http_read_headers.js
Normal file
|
@ -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));
|
||||
}
|
||||
})();
|
||||
}
|
5
cli/bench/http/deno_http_read_headers.lua
Normal file
5
cli/bench/http/deno_http_read_headers.lua
Normal file
|
@ -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"
|
19
cli/bench/http/deno_post_json.js
Normal file
19
cli/bench/http/deno_post_json.js
Normal file
|
@ -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));
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
3
cli/bench/http/deno_post_json.lua
Normal file
3
cli/bench/http/deno_post_json.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
wrk.method = "POST"
|
||||
wrk.headers["Content-Type"] = "application/json"
|
||||
wrk.body = '{"hello":"deno"}'
|
10
cli/bench/http/node_http_read_headers.js
Normal file
10
cli/bench/http/node_http_read_headers.js
Normal file
|
@ -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);
|
5
cli/bench/http/node_http_read_headers.lua
Normal file
5
cli/bench/http/node_http_read_headers.lua
Normal file
|
@ -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"
|
18
cli/bench/http/node_post_json.js
Normal file
18
cli/bench/http/node_post_json.js
Normal file
|
@ -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);
|
3
cli/bench/http/node_post_json.lua
Normal file
3
cli/bench/http/node_post_json.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
wrk.method = "POST"
|
||||
wrk.headers["Content-Type"] = "application/json"
|
||||
wrk.body = '{"hello":"node"}'
|
Loading…
Reference in a new issue