1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
use criterion::*;
fn criterion_benchmark(c: &mut Criterion) {
let threads = num_cpus::get().max(1);
let tasks = 1000;
let mut group = c.benchmark_group("pool");
group.sample_size(10);
group.bench_function("threadfin", |b| {
b.iter_batched(
|| threadfin::ThreadPool::builder().size(threads).build(),
|pool| {
for _ in 0..tasks {
pool.execute(|| {
let _ = black_box(8 + 9);
});
}
pool.join();
},
BatchSize::LargeInput,
);
});
group.bench_function("threadpool", |b| {
b.iter_batched(
|| threadpool::ThreadPool::new(threads),
|pool| {
for _ in 0..tasks {
pool.execute(|| {
let _ = black_box(8 + 9);
});
}
pool.join();
},
BatchSize::LargeInput,
);
});
group.bench_function("rusty_pool", |b| {
b.iter_batched(
|| rusty_pool::ThreadPool::new(threads, threads, std::time::Duration::ZERO),
|pool| {
for _ in 0..tasks {
pool.execute(|| {
let _ = black_box(8 + 9);
});
}
pool.shutdown_join();
},
BatchSize::LargeInput,
);
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
|