If for < is required To use clock , you need to add a bit of padding. At least on OS X, libc doesn't seem to set the clock , but it does give you clock_t (which is the more complicated part of the equation). The clock display is straightforward:
extern crate libc; mod ffi { extern { pub fn clock() -> ::libc::clock_t; } } fn main() { let start = unsafe { ffi::clock() }; let mut dummy = 0; for i in 0..20000 { dummy += i }; let end = unsafe { ffi::clock() }; println!("{}, {}, {}, {}", dummy, start, end, end - start); }
I would probably do a wrapper that marks clock as safe to call under any circumstances.
source share