Commit 63778789 authored by Simon Wörner's avatar Simon Wörner

added Measure

parent 1572b8ea
......@@ -4,4 +4,5 @@ version = "0.1.0"
authors = ["Simon Wörner <git@simon-woerner.de>"]
[dependencies]
time = "^0.1.36"
nix = "0.8.1"
\ No newline at end of file
pub mod gpio;
pub mod measure;
\ No newline at end of file
extern crate time;
use self::time::precise_time_ns;
#[derive(Debug)]
pub struct Measure {
pub min: u64,
pub max: u64,
time: u64,
pub name: String
}
impl Measure {
pub fn new(name: String) -> Self {
Measure {
min: u64::max_value(),
max: 0u64,
time: 064,
name: name
}
}
pub fn start(&mut self) {
if self.time != 0 {
#[cfg(debug_assertions)]
println!("WARNING: Measure('{:?}') start called without stop!", self);
}
self.time = precise_time_ns();
}
pub fn stop(&mut self) {
if self.time == 0 {
#[cfg(debug_assertions)]
println!("WARNING: Measure('{:?}') stop called without start!", self);
return;
}
let time_diff = precise_time_ns() - self.time;
if time_diff < self.min {
self.min = time_diff;
}
if time_diff > self.max {
self.max = time_diff;
}
self.time = 0u64;
}
}
impl Drop for Measure {
fn drop(&mut self) {
println!("{}:\n\tmin: {}\n\tmax: {}", self.name, self.min, self.max)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment