This code for hyper responds with exactly the same body and headers in size as fasthttp. On my computer, with LTO enabled, it performs much faster than go fasthttp.
use std::{convert::Infallible, net::SocketAddr};
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, SERVER};
const RESP: &str = "Welcome!";
async fn handle(_: Request<Body>) -> Result<Response<Body>, Infallible> {
let mut resp = Response::new(RESP.into());
resp
.headers_mut()
.insert(SERVER, "rusthttp".parse().unwrap());
resp
.headers_mut()
.insert(CONTENT_TYPE, "application/json".parse().unwrap());
resp
.headers_mut()
.insert(CONTENT_LENGTH, RESP.len().to_string().parse().unwrap());
Ok(resp)
}
#[tokio::main]
async fn main() {
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
let make_svc = make_service_fn(|_conn| async {
Ok::<_, Infallible>(service_fn(handle))
});
let server = Server::bind(&addr)
.serve(make_svc);
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
}
Updated my gist adding Hyper, routing in fasthttp and giving my go and rustc versions in doc. I still find fasthttp the best performer with these codes: gist.github.com/r0mdau/ac0f416d230...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This code for hyper responds with exactly the same body and headers in size as fasthttp. On my computer, with LTO enabled, it performs much faster than go fasthttp.
fasthttp:
hyper:
Updated my gist adding Hyper, routing in fasthttp and giving my go and rustc versions in doc. I still find fasthttp the best performer with these codes: gist.github.com/r0mdau/ac0f416d230...