Skip to content

Instantly share code, notes, and snippets.

@derekchiang
Created February 14, 2014 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekchiang/8994717 to your computer and use it in GitHub Desktop.
Save derekchiang/8994717 to your computer and use it in GitHub Desktop.
A benchmark of Rust libnative.
extern mod native;
extern mod extra;
extern mod sync;
use sync::mutex::{StaticMutex, MUTEX_INIT};
use std::os;
static mut LOCK: StaticMutex = MUTEX_INIT;
#[start]
fn start(argc: int, argv: **u8) -> int {
native::start(argc, argv, main)
}
#[inline(never)]
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!("native: {}s", end - start);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment