Created
February 14, 2014 02:22
-
-
Save derekchiang/8994717 to your computer and use it in GitHub Desktop.
A benchmark of Rust libnative.
This file contains 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 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