bench: Add benchmarks for lower thread counts (#38)
This commit is contained in:
parent
b8885f9578
commit
6aba704efc
|
@ -10,10 +10,12 @@ const LIGHT_TASKS: usize = 25_000;
|
|||
|
||||
static EX: Executor<'_> = Executor::new();
|
||||
|
||||
fn run(f: impl FnOnce()) {
|
||||
fn run(f: impl FnOnce(), multithread: bool) {
|
||||
let limit = if multithread { num_cpus::get() } else { 1 };
|
||||
|
||||
let (s, r) = async_channel::bounded::<()>(1);
|
||||
easy_parallel::Parallel::new()
|
||||
.each(0..num_cpus::get(), |_| future::block_on(EX.run(r.recv())))
|
||||
.each(0..limit, |_| future::block_on(EX.run(r.recv())))
|
||||
.finish(move || {
|
||||
let _s = s;
|
||||
f()
|
||||
|
@ -30,19 +32,24 @@ fn create(c: &mut Criterion) {
|
|||
});
|
||||
}
|
||||
|
||||
fn spawn_one(c: &mut Criterion) {
|
||||
c.bench_function("executor::spawn_one", |b| {
|
||||
run(|| {
|
||||
fn running_benches(c: &mut Criterion) {
|
||||
for (group_name, multithread) in [("single_thread", false), ("multi_thread", true)].iter() {
|
||||
let mut group = c.benchmark_group(group_name.to_string());
|
||||
|
||||
group.bench_function("executor::spawn_one", |b| {
|
||||
run(
|
||||
|| {
|
||||
b.iter(|| {
|
||||
future::block_on(async { EX.spawn(async {}).await });
|
||||
});
|
||||
},
|
||||
*multithread,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn_many(c: &mut Criterion) {
|
||||
c.bench_function("executor::spawn_many_local", |b| {
|
||||
run(|| {
|
||||
group.bench_function("executor::spawn_many_local", |b| {
|
||||
run(
|
||||
|| {
|
||||
b.iter(move || {
|
||||
future::block_on(async {
|
||||
let mut tasks = Vec::new();
|
||||
|
@ -54,12 +61,12 @@ fn spawn_many(c: &mut Criterion) {
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
*multithread,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn_recursively(c: &mut Criterion) {
|
||||
c.bench_function("executor::spawn_recursively", |b| {
|
||||
group.bench_function("executor::spawn_recursively", |b| {
|
||||
#[allow(clippy::manual_async_fn)]
|
||||
fn go(i: usize) -> impl Future<Output = ()> + Send + 'static {
|
||||
async move {
|
||||
|
@ -73,7 +80,8 @@ fn spawn_recursively(c: &mut Criterion) {
|
|||
}
|
||||
}
|
||||
|
||||
run(|| {
|
||||
run(
|
||||
|| {
|
||||
b.iter(move || {
|
||||
future::block_on(async {
|
||||
let mut tasks = Vec::new();
|
||||
|
@ -85,13 +93,14 @@ fn spawn_recursively(c: &mut Criterion) {
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
*multithread,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn yield_now(c: &mut Criterion) {
|
||||
c.bench_function("executor::yield_now", |b| {
|
||||
run(|| {
|
||||
group.bench_function("executor::yield_now", |b| {
|
||||
run(
|
||||
|| {
|
||||
b.iter(move || {
|
||||
future::block_on(async {
|
||||
let mut tasks = Vec::new();
|
||||
|
@ -107,17 +116,13 @@ fn yield_now(c: &mut Criterion) {
|
|||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
*multithread,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
create,
|
||||
spawn_one,
|
||||
spawn_many,
|
||||
spawn_recursively,
|
||||
yield_now,
|
||||
);
|
||||
criterion_group!(benches, create, running_benches);
|
||||
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Reference in New Issue