summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2018-03-31 15:40:16 +0900
committerPaul Masurel <paul.masurel@gmail.com>2018-03-31 15:40:16 +0900
commit0107fe886b014e49613173a0cec3bdc7a3c8208d (patch)
tree2e533e6c5754f13bc60f23bd3b334ee0ae3e6a19 /src/common
parent1d9566e73cd6947e371d9d2b7ca1ba93998404cd (diff)
Removed timer
Diffstat (limited to 'src/common')
-rw-r--r--src/common/mod.rs6
-rw-r--r--src/common/timer.rs99
2 files changed, 1 insertions, 104 deletions
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 66e4bbf..fb50422 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -1,5 +1,4 @@
-mod serialize;
-mod timer;
+ mod serialize;
mod vint;
mod counting_writer;
mod composite_file;
@@ -8,9 +7,6 @@ mod bitset;
pub(crate) use self::composite_file::{CompositeFile, CompositeWrite};
pub use self::serialize::{BinarySerializable, FixedSize};
-pub use self::timer::Timing;
-pub use self::timer::TimerTree;
-pub use self::timer::OpenTimer;
pub use self::vint::VInt;
pub use self::counting_writer::CountingWriter;
pub use self::bitset::BitSet;
diff --git a/src/common/timer.rs b/src/common/timer.rs
deleted file mode 100644
index 9563810..0000000
--- a/src/common/timer.rs
+++ /dev/null
@@ -1,99 +0,0 @@
-use time::PreciseTime;
-
-pub struct OpenTimer<'a> {
- name: &'static str,
- timer_tree: &'a mut TimerTree,
- start: PreciseTime,
- depth: u32,
-}
-
-impl<'a> OpenTimer<'a> {
- /// Starts timing a new named subtask
- ///
- /// The timer is stopped automatically
- /// when the `OpenTimer` is dropped.
- pub fn open(&mut self, name: &'static str) -> OpenTimer {
- OpenTimer {
- name,
- timer_tree: self.timer_tree,
- start: PreciseTime::now(),
- depth: self.depth + 1,
- }
- }
-}
-
-impl<'a> Drop for OpenTimer<'a> {
- fn drop(&mut self) {
- self.timer_tree.timings.push(Timing {
- name: self.name,
- duration: self.start
- .to(PreciseTime::now())
- .num_microseconds()
- .unwrap(),
- depth: self.depth,
- });
- }
-}
-
-/// Timing recording
-#[derive(Debug, Serialize)]
-pub struct Timing {
- name: &'static str,
- duration: i64,
- depth: u32,
-}
-
-/// Timer tree
-#[derive(Debug, Serialize)]
-pub struct TimerTree {
- timings: Vec<Timing>,
-}
-
-impl TimerTree {
- /// Returns the total time elapsed in microseconds
- pub fn total_time(&self) -> i64 {
- self.timings.last().unwrap().duration
- }
-
- /// Open a new named subtask
- pub fn open(&mut self, name: &'static str) -> OpenTimer {
- OpenTimer {
- name,
- timer_tree: self,
- start: PreciseTime::now(),
- depth: 0,
- }
- }
-}
-
-impl Default for TimerTree {
- fn default() -> TimerTree {
- TimerTree {
- timings: Vec::new(),
- }
- }
-}
-
-#[cfg(test)]
-mod tests {
-
- use super::*;
-
- #[test]
- fn test_timer() {
- let mut timer_tree = TimerTree::default();
- {
- let mut a = timer_tree.open("a");
- {
- let mut ab = a.open("b");
- {
- let _abc = ab.open("c");
- }
- {
- let _abd = ab.open("d");
- }
- }
- }
- assert_eq!(timer_tree.timings.len(), 4);
- }
-}