(fix) Update examples and benchmarks to remove rust-http.
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
// You have to ctrl-C after running this benchmark, since there is no way to kill
|
||||
// a rust-http server.
|
||||
|
||||
extern crate http;
|
||||
extern crate hyper;
|
||||
extern crate test;
|
||||
|
||||
use test::Bencher;
|
||||
use std::io::net::ip::{SocketAddr, Ipv4Addr};
|
||||
use std::io::net::ip::Ipv4Addr;
|
||||
|
||||
use http::server::Server;
|
||||
use hyper::method::Method::Get;
|
||||
use hyper::server::{Request, Response};
|
||||
|
||||
@@ -35,36 +30,3 @@ fn bench_hyper(b: &mut Bencher) {
|
||||
listener.close().unwrap();
|
||||
}
|
||||
|
||||
static mut created_http: bool = false;
|
||||
|
||||
#[deriving(Clone)]
|
||||
struct HttpServer;
|
||||
|
||||
impl Server for HttpServer {
|
||||
fn get_config(&self) -> http::server::Config {
|
||||
http::server::Config {
|
||||
bind_address: SocketAddr {
|
||||
ip: Ipv4Addr(127, 0, 0, 1),
|
||||
port: 4000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_request(&self, _: http::server::Request, res: &mut http::server::ResponseWriter) {
|
||||
res.write(PHRASE).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_http(b: &mut Bencher) {
|
||||
if unsafe { !created_http } {
|
||||
spawn(proc() { HttpServer.serve_forever() });
|
||||
unsafe { created_http = true }
|
||||
// Mega hack because there is no way to wait for serve_forever to start:
|
||||
std::io::timer::sleep(std::time::duration::Duration::seconds(1));
|
||||
}
|
||||
|
||||
let url = hyper::Url::parse("http://localhost:4000").unwrap();
|
||||
b.iter(|| request(url.clone()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user