summaryrefslogtreecommitdiff
path: root/cli/bench
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-04-09 00:34:15 +0200
committerGitHub <noreply@github.com>2021-04-08 18:34:15 -0400
commit70af8128767f2fc5a9c59107d3b5ddc00531db55 (patch)
tree48513959f16273eab2c4b743d61042b00a72deb8 /cli/bench
parentb30ac9c5cf58c34ed71d2f470cdbcd86a6096987 (diff)
feat: native HTTP bindings (#9935)
Co-authered-by: Luca Casonato <lucacasonato@yahoo.com> Co-authered-by: Ben Noordhuis <info@bnoordhuis.nl> Co-authered-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'cli/bench')
-rw-r--r--cli/bench/deno_http_native.js17
-rw-r--r--cli/bench/http.rs20
2 files changed, 37 insertions, 0 deletions
diff --git a/cli/bench/deno_http_native.js b/cli/bench/deno_http_native.js
new file mode 100644
index 000000000..fa779be21
--- /dev/null
+++ b/cli/bench/deno_http_native.js
@@ -0,0 +1,17 @@
+// Copyright 2018-2021 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);
+
+const body = Deno.core.encode("Hello World");
+
+for await (const conn of listener) {
+ (async () => {
+ const requests = Deno.startHttp(conn);
+ for await (const { respondWith } of requests) {
+ respondWith(new Response(body));
+ }
+ })();
+}
diff --git a/cli/bench/http.rs b/cli/bench/http.rs
index 952f3f19b..690e26cf4 100644
--- a/cli/bench/http.rs
+++ b/cli/bench/http.rs
@@ -33,6 +33,7 @@ pub(crate) fn benchmark(
res.insert("deno_tcp".to_string(), deno_tcp(deno_exe)?);
// res.insert("deno_udp".to_string(), deno_udp(deno_exe)?);
res.insert("deno_http".to_string(), deno_http(deno_exe)?);
+ res.insert("deno_http_native".to_string(), deno_http_native(deno_exe)?);
// TODO(ry) deno_proxy disabled to make fetch() standards compliant.
// res.insert("deno_proxy".to_string(), deno_http_proxy(deno_exe) hyper_hello_exe))
res.insert(
@@ -200,6 +201,25 @@ fn deno_http(deno_exe: &str) -> Result<HttpBenchmarkResult> {
)
}
+fn deno_http_native(deno_exe: &str) -> Result<HttpBenchmarkResult> {
+ let port = get_port();
+ println!("http_benchmark testing DENO using native bindings.");
+ run(
+ &[
+ deno_exe,
+ "run",
+ "--allow-net",
+ "--reload",
+ "--unstable",
+ "cli/bench/deno_http_native.js",
+ &server_addr(port),
+ ],
+ port,
+ None,
+ None,
+ )
+}
+
#[allow(dead_code)]
fn deno_http_proxy(
deno_exe: &str,