-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility type WakerSet to the sync module (#390)
* 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
Showing
7 changed files
with
371 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {})); | ||
} |
Oops, something went wrong.