mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00

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.
74 lines
1.8 KiB
Rust
74 lines
1.8 KiB
Rust
#![feature(test)]
|
|
#![deny(warnings)]
|
|
|
|
extern crate tokio_threadpool;
|
|
extern crate futures;
|
|
extern crate futures_cpupool;
|
|
extern crate num_cpus;
|
|
extern crate test;
|
|
|
|
const ITER: usize = 20_000;
|
|
|
|
mod us {
|
|
use tokio_threadpool::*;
|
|
use futures::future;
|
|
use test;
|
|
use std::sync::mpsc;
|
|
|
|
#[bench]
|
|
fn chained_spawn(b: &mut test::Bencher) {
|
|
let threadpool = ThreadPool::new();
|
|
|
|
fn spawn(pool_tx: Sender, res_tx: mpsc::Sender<()>, n: usize) {
|
|
if n == 0 {
|
|
res_tx.send(()).unwrap();
|
|
} else {
|
|
let pool_tx2 = pool_tx.clone();
|
|
pool_tx.spawn(future::lazy(move || {
|
|
spawn(pool_tx2, res_tx, n - 1);
|
|
Ok(())
|
|
})).unwrap();
|
|
}
|
|
}
|
|
|
|
b.iter(move || {
|
|
let (res_tx, res_rx) = mpsc::channel();
|
|
|
|
spawn(threadpool.sender().clone(), res_tx, super::ITER);
|
|
res_rx.recv().unwrap();
|
|
});
|
|
}
|
|
}
|
|
|
|
mod cpupool {
|
|
use futures::future::{self, Executor};
|
|
use futures_cpupool::*;
|
|
use num_cpus;
|
|
use test;
|
|
use std::sync::mpsc;
|
|
|
|
#[bench]
|
|
fn chained_spawn(b: &mut test::Bencher) {
|
|
let pool = CpuPool::new(num_cpus::get());
|
|
|
|
fn spawn(pool: CpuPool, res_tx: mpsc::Sender<()>, n: usize) {
|
|
if n == 0 {
|
|
res_tx.send(()).unwrap();
|
|
} else {
|
|
let pool2 = pool.clone();
|
|
pool.execute(future::lazy(move || {
|
|
spawn(pool2, res_tx, n - 1);
|
|
Ok(())
|
|
})).ok().unwrap();
|
|
}
|
|
}
|
|
|
|
b.iter(move || {
|
|
let (res_tx, res_rx) = mpsc::channel();
|
|
|
|
spawn(pool.clone(), res_tx, super::ITER);
|
|
res_rx.recv().unwrap();
|
|
});
|
|
}
|
|
}
|