ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        new-ast
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since c5c743e was             51493a4, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago | 
        
          | 
start directory for full-contention mutex tests
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            547 bytes | 
      
      
| Line |  | 
|---|
| 1 | use std::env; | 
|---|
| 2 | use std::process; | 
|---|
| 3 | use std::sync::Mutex; | 
|---|
| 4 | use std::time::Instant; | 
|---|
| 5 |  | 
|---|
| 6 | fn call( lock : & Mutex<u32> ) { | 
|---|
| 7 | let _ = lock.lock(); | 
|---|
| 8 | } | 
|---|
| 9 |  | 
|---|
| 10 | fn main() { | 
|---|
| 11 | let mut times : u32 = 50000000; | 
|---|
| 12 | let args: Vec<String> = env::args().collect(); | 
|---|
| 13 | if args.len() > 2 { process::exit( 1 ); } | 
|---|
| 14 | if args.len() == 2 { times = args[1].parse().unwrap(); } | 
|---|
| 15 |  | 
|---|
| 16 | let lock = Mutex::new(0); | 
|---|
| 17 |  | 
|---|
| 18 | let start = Instant::now(); | 
|---|
| 19 | for _ in 1..times { | 
|---|
| 20 | call( &lock ); | 
|---|
| 21 | } | 
|---|
| 22 | let duration = start.elapsed() / times; | 
|---|
| 23 | println!( "{:?}", duration.as_nanos() ) | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | // rustc -C opt-level=3 rust.rs | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.