Last change
on this file since b59c21a was
b4107c8,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
update existing benchmarks for changes to bench.h, add new benchmarks in new programming languages
|
-
Property mode set to
100644
|
File size:
622 bytes
|
Rev | Line | |
---|
[b4107c8] | 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 | // Local Variables: // |
---|
| 27 | // tab-width: 4 // |
---|
| 28 | // compile-command: "rustc -C opt-level=3 rust.rs" // |
---|
| 29 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.