#[macro_use] extern crate r; #[test] fn test_microbench() { let tsc_hz = r::asm::calc_tsc_hz(); let end_at = r::asm::rdtsc_arch() + 5 * tsc_hz; while r::asm::rdtsc_arch() < end_at { { DO_MICROBENCH!(); } { DO_MICROBENCH!( "Custom test name with default timestamp", tsc_hz, r::microbench::DEFAULT_TIMESTAMP_FUNC ); } { DO_MICROBENCH!( "Custom test name with rdtsc timestamp", tsc_hz, r::asm::rdtsc_arch ); } { DO_MICROBENCH!( "Custom test name with precise rdtsc timestamp", tsc_hz, r::asm::rdtsc_precise ); } { DO_MICROBENCH_WITH_INTERVAL!(tsc_hz); } { DO_MICROBENCH_WITH_NAME!("Custom WITH_NAME"); } { DO_MICROBENCH_WITH_NAME_INTERVAL!("Custom WITH_NAME_INTERVAL", tsc_hz); } } } #[test] fn test_path_bench() { let tsc_hz = r::asm::calc_tsc_hz(); let end_at = r::asm::rdtsc_arch() + 5 * tsc_hz; let mut i = 0usize; while r::asm::rdtsc_arch() < end_at { { DO_PATH_BENCH!(); if i % 7 == 0 { MEASURE_PATH_WITH_NAME!("zero: 1/7"); } else if i % 7 == 1 { MEASURE_PATH_WITH_NAME!("one: 1/7"); } else { MEASURE_PATH_WITH_NAME!("others: 5/7"); } } { DO_PATH_BENCH_WITH_INTERVAL!(tsc_hz); match i % 7 { 0 => { MEASURE_PATH!(); } 1 => { MEASURE_PATH!(); } _ => { MEASURE_PATH!(); } } } { DO_PATH_BENCH_WITH_NAME_INTERVAL!("PathTest2", tsc_hz); match i % 7 { 0 => { MEASURE_PATH!(); } 1 => { MEASURE_PATH!(); } _ => { MEASURE_PATH!(); } } } { DO_PATH_BENCH_WITH_NAME!("PathTest3"); { if i % 7 == 0 { Ok(0) } else { Err(0) } } .and_then(|_| { MEASURE_PATH!("Ok"); Ok(()) }) .unwrap_or_else(|_| { MEASURE_PATH!("Err"); }); } i += 1; } }