Skip to content

Commit 87de4e1

Browse files
author
Stjepan Glavina
authored
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
1 parent 3dd59d7 commit 87de4e1

File tree

7 files changed

+371
-348
lines changed

7 files changed

+371
-348
lines changed

benches/mutex.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![feature(test)]
2+
3+
extern crate test;
4+
5+
use std::sync::Arc;
6+
7+
use async_std::sync::Mutex;
8+
use async_std::task;
9+
use test::Bencher;
10+
11+
#[bench]
12+
fn create(b: &mut Bencher) {
13+
b.iter(|| Mutex::new(()));
14+
}
15+
16+
#[bench]
17+
fn contention(b: &mut Bencher) {
18+
b.iter(|| task::block_on(run(10, 1000)));
19+
}
20+
21+
#[bench]
22+
fn no_contention(b: &mut Bencher) {
23+
b.iter(|| task::block_on(run(1, 10000)));
24+
}
25+
26+
async fn run(task: usize, iter: usize) {
27+
let m = Arc::new(Mutex::new(()));
28+
let mut tasks = Vec::new();
29+
30+
for _ in 0..task {
31+
let m = m.clone();
32+
tasks.push(task::spawn(async move {
33+
for _ in 0..iter {
34+
let _ = m.lock().await;
35+
}
36+
}));
37+
}
38+
39+
for t in tasks {
40+
t.await;
41+
}
42+
}

benches/task.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(test)]
2+
3+
extern crate test;
4+
5+
use async_std::task;
6+
use test::Bencher;
7+
8+
#[bench]
9+
fn block_on(b: &mut Bencher) {
10+
b.iter(|| task::block_on(async {}));
11+
}

0 commit comments

Comments
 (0)