Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A benchmark of Rust libgreen.
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