From 1f91a890b4ff6f3707970d1c15350469f72c1a68 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 6 Mar 2018 14:40:09 -0800 Subject: Fix benches (#188) Some of the benchhmarks were broken and/or using deprecated APIs. This patch updates the benches and requires them all to compile without warnings in order to pass CI. --- .travis.yml | 2 +- benches/latency.rs | 8 ++++---- benches/mio-ops.rs | 1 + benches/tcp.rs | 1 + tokio-threadpool/benches/basic.rs | 22 +++++++++++----------- tokio-threadpool/benches/depth.rs | 21 +++++++++++---------- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index e7365da5..09868a0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ script: - | if [[ "$TRAVIS_RUST_VERSION" == nightly ]] then - cargo build --benches + cargo build --benches --all fi - cargo test --all diff --git a/benches/latency.rs b/benches/latency.rs index f35cb793..c2619b71 100644 --- a/benches/latency.rs +++ b/benches/latency.rs @@ -1,10 +1,10 @@ #![feature(test)] +#![deny(warnings)] extern crate test; +#[macro_use] extern crate futures; extern crate tokio; -#[macro_use] -extern crate tokio_io; use std::io; use std::net::SocketAddr; @@ -40,10 +40,10 @@ impl Future for EchoServer { fn poll(&mut self) -> Poll<(), io::Error> { loop { if let Some(&(size, peer)) = self.to_send.as_ref() { - try_nb!(self.socket.send_to(&self.buf[..size], &peer)); + try_ready!(self.socket.poll_send_to(&self.buf[..size], &peer)); self.to_send = None; } - self.to_send = Some(try_nb!(self.socket.recv_from(&mut self.buf))); + self.to_send = Some(try_ready!(self.socket.poll_recv_from(&mut self.buf))); } } } diff --git a/benches/mio-ops.rs b/benches/mio-ops.rs index 6a74879c..6a71bebf 100644 --- a/benches/mio-ops.rs +++ b/benches/mio-ops.rs @@ -1,6 +1,7 @@ // Measure cost of different operations // to get a sense of performance tradeoffs #![feature(test)] +#![deny(warnings)] extern crate test; extern crate mio; diff --git a/benches/tcp.rs b/benches/tcp.rs index 37467d8a..45ff3711 100644 --- a/benches/tcp.rs +++ b/benches/tcp.rs @@ -1,4 +1,5 @@ #![feature(test)] +#![deny(warnings)] extern crate futures; extern crate tokio; diff --git a/tokio-threadpool/benches/basic.rs b/tokio-threadpool/benches/basic.rs index 7217ce0f..83504866 100644 --- a/tokio-threadpool/benches/basic.rs +++ b/tokio-threadpool/benches/basic.rs @@ -1,7 +1,8 @@ #![feature(test)] +#![deny(warnings)] +extern crate tokio_threadpool; extern crate futures; -extern crate futures_pool; extern crate futures_cpupool; extern crate num_cpus; extern crate test; @@ -10,10 +11,9 @@ const NUM_SPAWN: usize = 10_000; const NUM_YIELD: usize = 1_000; const TASKS_PER_CPU: usize = 50; -mod us { - use futures::{task, Async}; - use futures::future::{self, Executor}; - use futures_pool::*; +mod threadpool { + use futures::{future, task, Async}; + use tokio_threadpool::*; use num_cpus; use test; use std::sync::{mpsc, Arc}; @@ -22,7 +22,7 @@ mod us { #[bench] fn spawn_many(b: &mut test::Bencher) { - let (sched_tx, _scheduler) = Pool::new(); + let threadpool = ThreadPool::new(); let (tx, rx) = mpsc::sync_channel(10); let rem = Arc::new(AtomicUsize::new(0)); @@ -34,13 +34,13 @@ mod us { let tx = tx.clone(); let rem = rem.clone(); - sched_tx.execute(future::lazy(move || { + threadpool.spawn(future::lazy(move || { if 1 == rem.fetch_sub(1, SeqCst) { tx.send(()).unwrap(); } Ok(()) - })).ok().unwrap(); + })); } let _ = rx.recv().unwrap(); @@ -49,7 +49,7 @@ mod us { #[bench] fn yield_many(b: &mut test::Bencher) { - let (sched_tx, _scheduler) = Pool::new(); + let threadpool = ThreadPool::new(); let tasks = super::TASKS_PER_CPU * num_cpus::get(); let (tx, rx) = mpsc::sync_channel(tasks); @@ -59,7 +59,7 @@ mod us { let mut rem = super::NUM_YIELD; let tx = tx.clone(); - sched_tx.execute(future::poll_fn(move || { + threadpool.spawn(future::poll_fn(move || { rem -= 1; if rem == 0 { @@ -72,7 +72,7 @@ mod us { // Not ready Ok(Async::NotReady) } - })).ok().unwrap(); + })); } for _ in 0..tasks { diff --git a/tokio-threadpool/benches/depth.rs b/tokio-threadpool/benches/depth.rs index 2e378beb..d500ad4a 100644 --- a/tokio-threadpool/benches/depth.rs +++ b/tokio-threadpool/benches/depth.rs @@ -1,7 +1,8 @@ #![feature(test)] +#![deny(warnings)] +extern crate tokio_threadpool; extern crate futures; -extern crate futures_pool; extern crate futures_cpupool; extern crate num_cpus; extern crate test; @@ -9,31 +10,31 @@ extern crate test; const ITER: usize = 20_000; mod us { - use futures::future::{self, Executor}; - use futures_pool::*; + use tokio_threadpool::*; + use futures::future; use test; use std::sync::mpsc; #[bench] fn chained_spawn(b: &mut test::Bencher) { - let (sched_tx, _scheduler) = Pool::new(); + let threadpool = ThreadPool::new(); - fn spawn(sched_tx: Sender, res_tx: mpsc::Sender<()>, n: usize) { + fn spawn(pool_tx: Sender, res_tx: mpsc::Sender<()>, n: usize) { if n == 0 { res_tx.send(()).unwrap(); } else { - let sched_tx2 = sched_tx.clone(); - sched_tx.execute(future::lazy(move || { - spawn(sched_tx2, res_tx, n - 1); + let pool_tx2 = pool_tx.clone(); + pool_tx.spawn(future::lazy(move || { + spawn(pool_tx2, res_tx, n - 1); Ok(()) - })).ok().unwrap(); + })).unwrap(); } } b.iter(move || { let (res_tx, res_rx) = mpsc::channel(); - spawn(sched_tx.clone(), res_tx, super::ITER); + spawn(threadpool.sender().clone(), res_tx, super::ITER); res_rx.recv().unwrap(); }); } -- cgit v1.2.3