Skip to content

Instantly share code, notes, and snippets.

@erikdesjardins
Created December 20, 2020 05:11
Show Gist options
  • Save erikdesjardins/0d3d19194c85fdf3557d9955fd54f605 to your computer and use it in GitHub Desktop.
Save erikdesjardins/0d3d19194c85fdf3557d9955fd54f605 to your computer and use it in GitHub Desktop.
old hyper str comparison benchmark
[package]
name = "hyper-test"
version = "0.1.0"
authors = []
edition = "2018"
[dependencies]
hyper = { version = "=0.9.4", default-features = false }
[features]
enum = []
use hyper::Server;
use hyper::method::Method;
use hyper::server::Request;
use hyper::server::Response;
#[cfg(not(feature = "enum"))]
fn hello(req: Request, res: Response) {
if req.method.as_ref() == "GET" {
res.send(b"Hello World!").unwrap();
} else {
panic!("only can handle GET")
}
}
#[cfg(feature = "enum")]
fn hello(req: Request, res: Response) {
if req.method == Method::Get {
res.send(b"Hello World!").unwrap();
} else {
panic!("only can handle GET")
}
}
fn main() {
Server::http("127.0.0.1:3000").unwrap()
.handle(hello).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment