source:
benchmark/mutexC/rust.rs
@
32d1383
Last change on this file since 32d1383 was 51493a4, checked in by , 5 years ago | |
---|---|
|
|
File size: 547 bytes |
Rev | Line | |
---|---|---|
[51493a4] | 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.