Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej committed Sep 8, 2023
1 parent 9760b7c commit 4bce885
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
20 changes: 10 additions & 10 deletions benches/sync_mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,39 +163,39 @@ fn uncontented_unbounded(g: &mut BenchmarkGroup<WallTime>) {
});
}

fn group_create_medium(c: &mut Criterion) {
fn bench_create_medium(c: &mut Criterion) {
let mut group = c.benchmark_group("create_medium");
create_medium::<1>(&mut group);
create_medium::<100>(&mut group);
create_medium::<100_000>(&mut group);
group.finish();
}

fn group_send(c: &mut Criterion) {
fn bench_send(c: &mut Criterion) {
let mut group = c.benchmark_group("send");
send_data::<Medium, 1000>(&mut group, "Medium");
send_data::<Large, 1000>(&mut group, "Medium");
send_data::<Medium, 1000>(&mut group, "medium");
send_data::<Large, 1000>(&mut group, "large");
group.finish();
}

fn group_contention(c: &mut Criterion) {
fn bench_contention(c: &mut Criterion) {
let mut group = c.benchmark_group("contention");
contention_bounded(&mut group);
contention_bounded_full(&mut group);
contention_unbounded(&mut group);
group.finish();
}

fn group_uncontented(c: &mut Criterion) {
fn bench_uncontented(c: &mut Criterion) {
let mut group = c.benchmark_group("uncontented");
uncontented_bounded(&mut group);
uncontented_unbounded(&mut group);
group.finish();
}

criterion_group!(create, group_create_medium);
criterion_group!(send, group_send);
criterion_group!(contention, group_contention);
criterion_group!(uncontented, group_uncontented);
criterion_group!(create, bench_create_medium);
criterion_group!(send, bench_send);
criterion_group!(contention, bench_contention);
criterion_group!(uncontented, bench_uncontented);

criterion_main!(create, send, contention, uncontented);
8 changes: 4 additions & 4 deletions benches/sync_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn notify_one<const N_WAITERS: usize>(g: &mut BenchmarkGroup<WallTime>) {
});
}

fn group_notify_one(c: &mut Criterion) {
fn bench_notify_one(c: &mut Criterion) {
let mut group = c.benchmark_group("notify_one");
notify_one::<10>(&mut group);
notify_one::<50>(&mut group);
Expand All @@ -85,7 +85,7 @@ fn group_notify_one(c: &mut Criterion) {
group.finish();
}

fn group_notify_waiters(c: &mut Criterion) {
fn bench_notify_waiters(c: &mut Criterion) {
let mut group = c.benchmark_group("notify_waiters");
notify_waiters::<10>(&mut group);
notify_waiters::<50>(&mut group);
Expand All @@ -97,8 +97,8 @@ fn group_notify_waiters(c: &mut Criterion) {

criterion_group!(
notify_waiters_simple,
group_notify_one,
group_notify_waiters
bench_notify_one,
bench_notify_waiters
);

criterion_main!(notify_waiters_simple);
8 changes: 4 additions & 4 deletions benches/sync_rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,22 @@ fn read_concurrent_contended(g: &mut BenchmarkGroup<WallTime>) {
});
}

fn group_contention(c: &mut Criterion) {
fn bench_contention(c: &mut Criterion) {
let mut group = c.benchmark_group("contention");
read_concurrent_contended(&mut group);
read_concurrent_contended_multi(&mut group);
group.finish();
}

fn group_uncontented(c: &mut Criterion) {
fn bench_uncontented(c: &mut Criterion) {
let mut group = c.benchmark_group("uncontented");
read_uncontended(&mut group);
read_concurrent_uncontended(&mut group);
read_concurrent_uncontended_multi(&mut group);
group.finish();
}

criterion_group!(contention, group_contention);
criterion_group!(uncontented, group_uncontented);
criterion_group!(contention, bench_contention);
criterion_group!(uncontented, bench_uncontented);

criterion_main!(contention, uncontented);
43 changes: 22 additions & 21 deletions benches/sync_semaphore.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
use std::sync::Arc;
use tokio::runtime::Runtime;
use tokio::{sync::Semaphore, task};

use criterion::measurement::WallTime;
use criterion::{criterion_group, criterion_main, BenchmarkGroup, Criterion};

fn uncontended(g: &mut BenchmarkGroup<WallTime>) {
let rt = tokio::runtime::Builder::new_multi_thread()
fn single_rt() -> Runtime {
tokio::runtime::Builder::new_current_thread()
.build()
.unwrap()
}

fn multi_rt() -> Runtime {
tokio::runtime::Builder::new_multi_thread()
.worker_threads(6)
.build()
.unwrap();
.unwrap()
}

fn uncontended(g: &mut BenchmarkGroup<WallTime>) {
let rt = multi_rt();

let s = Arc::new(Semaphore::new(10));
g.bench_function("multi", |b| {
Expand All @@ -30,10 +41,7 @@ async fn task(s: Arc<Semaphore>) {
}

fn uncontended_concurrent_multi(g: &mut BenchmarkGroup<WallTime>) {
let rt = tokio::runtime::Builder::new_multi_thread()
.worker_threads(6)
.build()
.unwrap();
let rt = multi_rt();

let s = Arc::new(Semaphore::new(10));
g.bench_function("concurrent_multi", |b| {
Expand All @@ -55,9 +63,7 @@ fn uncontended_concurrent_multi(g: &mut BenchmarkGroup<WallTime>) {
}

fn uncontended_concurrent_single(g: &mut BenchmarkGroup<WallTime>) {
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();
let rt = single_rt();

let s = Arc::new(Semaphore::new(10));
g.bench_function("concurrent_single", |b| {
Expand All @@ -78,10 +84,7 @@ fn uncontended_concurrent_single(g: &mut BenchmarkGroup<WallTime>) {
}

fn contended_concurrent_multi(g: &mut BenchmarkGroup<WallTime>) {
let rt = tokio::runtime::Builder::new_multi_thread()
.worker_threads(6)
.build()
.unwrap();
let rt = multi_rt();

let s = Arc::new(Semaphore::new(5));
g.bench_function("concurrent_multi", |b| {
Expand All @@ -103,9 +106,7 @@ fn contended_concurrent_multi(g: &mut BenchmarkGroup<WallTime>) {
}

fn contended_concurrent_single(g: &mut BenchmarkGroup<WallTime>) {
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();
let rt = single_rt();

let s = Arc::new(Semaphore::new(5));
g.bench_function("concurrent_single", |b| {
Expand All @@ -125,22 +126,22 @@ fn contended_concurrent_single(g: &mut BenchmarkGroup<WallTime>) {
});
}

fn group_contention(c: &mut Criterion) {
fn bench_contention(c: &mut Criterion) {
let mut group = c.benchmark_group("contention");
contended_concurrent_multi(&mut group);
contended_concurrent_single(&mut group);
group.finish();
}

fn group_uncontented(c: &mut Criterion) {
fn bench_uncontented(c: &mut Criterion) {
let mut group = c.benchmark_group("uncontented");
uncontended(&mut group);
uncontended_concurrent_multi(&mut group);
uncontended_concurrent_single(&mut group);
group.finish();
}

criterion_group!(contention, group_contention);
criterion_group!(uncontented, group_uncontented);
criterion_group!(contention, bench_contention);
criterion_group!(uncontented, bench_uncontented);

criterion_main!(contention, uncontented);

0 comments on commit 4bce885

Please sign in to comment.