Created
February 14, 2014 02:20
-
-
Save derekchiang/8994707 to your computer and use it in GitHub Desktop.
A benchmark of Rust libgreen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern mod extra; | |
extern mod sync; | |
use sync::mutex::{StaticMutex, MUTEX_INIT}; | |
use std::os; | |
static mut LOCK: StaticMutex = MUTEX_INIT; | |
fn work() { | |
for _ in range(0, 10000000) { | |
unsafe { | |
LOCK.lock(); | |
} | |
} | |
} | |
fn main() { | |
let start = extra::time::precise_time_s(); | |
let args = os::args(); | |
let mut threads = 1; | |
if args.len() > 1 { | |
threads = FromStr::from_str(args[1]).unwrap(); | |
} | |
let (p, c) = Chan::new(); | |
for _ in range(0, threads) { | |
let c = c.clone(); | |
spawn(proc() { | |
work(); | |
c.send(()); | |
}) | |
} | |
drop(c); | |
for _ in range(0, threads) { | |
p.recv(); | |
} | |
let end = extra::time::precise_time_s(); | |
println!("green: {}s", end - start); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment