Skip to content

Commit

Permalink
Add utility type WakerSet to the sync module (#390)
Browse files Browse the repository at this point in the history
* Add utility type Registry to the sync module

* Remove unused import

* Split unregister into complete and cancel

* Refactoring and renaming

* Split remove() into complete() and cancel()

* Rename to WakerSet

* Ignore clippy warning

* Ignore another clippy warning

* Use stronger SeqCst ordering
  • Loading branch information
Stjepan Glavina committed Nov 1, 2019
1 parent 3dd59d7 commit 87de4e1
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 348 deletions.
42 changes: 42 additions & 0 deletions benches/mutex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![feature(test)]

extern crate test;

use std::sync::Arc;

use async_std::sync::Mutex;
use async_std::task;
use test::Bencher;

#[bench]
fn create(b: &mut Bencher) {
b.iter(|| Mutex::new(()));
}

#[bench]
fn contention(b: &mut Bencher) {
b.iter(|| task::block_on(run(10, 1000)));
}

#[bench]
fn no_contention(b: &mut Bencher) {
b.iter(|| task::block_on(run(1, 10000)));
}

async fn run(task: usize, iter: usize) {
let m = Arc::new(Mutex::new(()));
let mut tasks = Vec::new();

for _ in 0..task {
let m = m.clone();
tasks.push(task::spawn(async move {
for _ in 0..iter {
let _ = m.lock().await;
}
}));
}

for t in tasks {
t.await;
}
}
11 changes: 11 additions & 0 deletions benches/task.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(test)]

extern crate test;

use async_std::task;
use test::Bencher;

#[bench]
fn block_on(b: &mut Bencher) {
b.iter(|| task::block_on(async {}));
}

0 comments on commit 87de4e1

Please sign in to comment.