summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn9
-rwxr-xr-xtools/benchmark.py3
-rwxr-xr-xtools/http_benchmark.py21
-rw-r--r--tools/hyper_hello.rs40
4 files changed, 67 insertions, 6 deletions
diff --git a/BUILD.gn b/BUILD.gn
index ef20cd1d2..cac34120f 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -13,6 +13,7 @@ group("default") {
deps = [
":deno",
":deno_ns",
+ ":hyper_hello",
":test_cc",
":test_rs",
]
@@ -137,6 +138,14 @@ rust_executable("deno_ns") {
]
}
+rust_executable("hyper_hello") {
+ source_root = "tools/hyper_hello.rs"
+ extern = [
+ "$rust_build:hyper",
+ "$rust_build:ring"
+ ]
+}
+
rust_test("test_rs") {
source_root = "src/main.rs"
extern = main_extern
diff --git a/tools/benchmark.py b/tools/benchmark.py
index 943883f8f..4bdd3b39a 100755
--- a/tools/benchmark.py
+++ b/tools/benchmark.py
@@ -184,8 +184,9 @@ def main(argv):
# Cannot run throughput benchmark on windows because they don't have nc or
# pipe.
if os.name != 'nt':
+ hyper_hello_path = os.path.join(build_dir, "hyper_hello")
new_data["throughput"] = run_throughput(deno_path)
- new_data["req_per_sec"] = http_benchmark(deno_path)
+ new_data["req_per_sec"] = http_benchmark(deno_path, hyper_hello_path)
if "linux" in sys.platform:
# Thread count test, only on linux
new_data["thread_count"] = run_thread_count_benchmark(deno_path)
diff --git a/tools/http_benchmark.py b/tools/http_benchmark.py
index 1fc78d31b..b90004396 100755
--- a/tools/http_benchmark.py
+++ b/tools/http_benchmark.py
@@ -16,17 +16,28 @@ def deno_http_benchmark(deno_exe):
return run(deno_cmd)
-def node_http_benchmark(deno_exe):
+def node_http_benchmark():
node_cmd = ["node", "tools/node_http.js", ADDR.split(":")[1]]
print "http_benchmark testing NODE."
return run(node_cmd)
-def http_benchmark(deno_exe):
- deno_rps = deno_http_benchmark(deno_exe)
- node_rps = node_http_benchmark(deno_exe)
+def hyper_http_benchmark(hyper_hello_exe):
+ hyper_cmd = [hyper_hello_exe, ADDR.split(":")[1]]
+ print "http_benchmark testing RUST hyper."
+ return run(hyper_cmd)
+
- return {"deno": deno_rps, "node": node_rps}
+def http_benchmark(deno_exe, hyper_hello_exe):
+ deno_rps = deno_http_benchmark(deno_exe)
+ node_rps = node_http_benchmark()
+ hyper_http_rps = hyper_http_benchmark(hyper_hello_exe)
+
+ return {
+ "deno": deno_rps,
+ "node": node_rps,
+ "hyper": hyper_http_rps
+ }
def run(server_cmd):
diff --git a/tools/hyper_hello.rs b/tools/hyper_hello.rs
new file mode 100644
index 000000000..08fc21b39
--- /dev/null
+++ b/tools/hyper_hello.rs
@@ -0,0 +1,40 @@
+// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+// Adapted from https://github.com/hyperium/hyper/blob/master/examples/hello.rs
+
+#![deny(warnings)]
+extern crate hyper;
+
+use std::env;
+use hyper::{Body, Response, Server};
+use hyper::service::service_fn_ok;
+use hyper::rt::{self, Future};
+
+static PHRASE: &'static [u8] = b"Hello World!";
+
+fn main() {
+ let mut port: u16 = 4544;
+ if let Some(custom_port) = env::args().nth(1) {
+ port = custom_port.parse::<u16>().unwrap();
+ }
+
+ let addr = ([127, 0, 0, 1], port).into();
+
+ // new_service is run for each connection, creating a 'service'
+ // to handle requests for that specific connection.
+ let new_service = || {
+ // This is the `Service` that will handle the connection.
+ // `service_fn_ok` is a helper to convert a function that
+ // returns a Response into a `Service`.
+ service_fn_ok(|_| {
+ Response::new(Body::from(PHRASE))
+ })
+ };
+
+ let server = Server::bind(&addr)
+ .serve(new_service)
+ .map_err(|e| eprintln!("server error: {}", e));
+
+ println!("Listening on http://{}", addr);
+
+ rt::run(server);
+}