mirror of
				https://github.com/async-rs/async-std.git
				synced 2025-11-04 02:36:39 +00:00 
			
		
		
		
	* 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
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			743 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			743 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
#![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;
 | 
						|
    }
 | 
						|
}
 |