Crate tid [] [src]

Maybe the simplest time taking crate there is.

The timed! macro prints the labels as {:<26} (left aligned, 26 char length). The only reason 26 is chosen is because my longest label happend to be around 26 chars long. The timings are printed as floating points in microseconds, for much of the same reasons. The exact print format is hardcoded as:

println!("[timed] {:<26} {:9.4}ms", label, (t1 - t0) as f64 / 1_000_000.0);

Examples

The crate has a macro timed! which is used for timing a block:

timed!("pushing some stuff",
    let mut v = Vec::new();
    for i in 0..100 {
        v.push(i);
    };     // note the `;` here
);
let q = v; // `v` is still reachable out here.

If you have multiple consecutive blocks, you can use Timer instead.

let mut t = Timer::new();
f();
t.mark("Doing f");
g();
t.mark("G is executed");
h();
t.mark("Done with H");
t.present();

Macros

timed

Time a block of code. For macro reasons, all blocks must be terminated by ;.

Structs

Timer

A Timer is used for timing multiple consecutive sections of your code. The first timing is done when the object is constructed. The second timing is done at the first call to mark. This time difference will be the one reported with the label you pass to mark.