[][src]Crate devtimer

Devtimer

devtimer provides a very compact yet complete benchmarking suite for code written in Rust. It makes use of the standard library only to provide benchmark operations. You can either use it for benchmarking a single operation or you can use it for running an operation multiple times and finding the min, max and average execution times. Since this crate has no external dependencies, it is small, fast and does exactly what it claims to. Happy benchmarking!

Examples: DevTime::new_simple()

use devtimer::DevTime;
fn main() {
    let mut devtime = DevTime::new_simple();
    devtime.start();
    // Do some long operation
    devtime.stop();
    println!("The time taken for the operation was: {} nanos", devtime.time_in_nanos().unwrap());
    println!("The time taken for the operation was: {} micros", devtime.time_in_micros().unwrap());
    println!("The time taken for the operation was: {} millis", devtime.time_in_millis().unwrap());
    println!("The time taken for the operation was: {} secs", devtime.time_in_secs().unwrap());
}

Example: devtimer::run_benchmark()

use devtimer::run_benchmark;
fn main() {
    // We will simulate a long operation by std::thread::sleep()
    // Run 10 iterations for the test
    let bench_result = run_benchmark(10, |_| {
        // Fake a long running operation
        std::thread::sleep(std::time::Duration::from_secs(1));
    });
    bench_result.print_stats();
}

Examples: DevTime::new_complex()

use devtimer::DevTime;
let mut dt = DevTime::new_complex();

// Create a new timer tag `pk12`
dt.create_timer("pk12").unwrap();
dt.start_timer("pk12").unwrap();
std::thread::sleep(std::time::Duration::from_micros(12));
dt.stop_timer("pk12").unwrap();
println!("The operation took: {} us", dt.time_in_micros("pk12").unwrap());

// Create a new timer tag `arg2`
dt.create_timer("arg2").unwrap();
dt.start_timer("arg2").unwrap();
std::thread::sleep(std::time::Duration::from_micros(45));
dt.stop_timer("arg2").unwrap();
println!("The operation took: {} us", dt.time_in_micros("arg2").unwrap());

// Use an iterator to iterate over timer and the resulting `SimpleTimer`
// to get times in nanos, micros, millis or secs.
for (timer, result) in dt.iter() {
    println!("Timer: {} - {}", timer, result.time_in_nanos().unwrap());
}

// Print '{timername} - {time in nanos}'
dt.print_results();
// Now delete all timers
dt.clear_timers();

Structs

ComplexTimer

Complex Timer

DevTime

The DevTime struct provides a simple implementation for benchmarking operations using the standard library.

RunThroughReport

The RunThroughReport struct provides a benchmark report when calling DevTime::run_benchmark(). You can get the slowest, fastest and the average time taken per iteration by the get_slowest(), get_fastest() and get_average() functions respectively.

SimpleTimer

The SimpleTimer struct holds the start and stop time instances

Functions

run_benchmark

The bench struct provides the benchmark function that can be used for benchmarking operations using the bench() member function Benchmark an operation by running multiple iterations. This function returns a RunThroughReport object which can be used to get the benchmark results.