File: mTimer.ml

package info (click to toggle)
planets 0.1.13-19
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 512 kB
  • sloc: ml: 4,541; makefile: 207; ansic: 38
file content (28 lines) | stat: -rw-r--r-- 742 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
type t = { mutable start_time : float;
	   mutable stop_time : float; 
	   mutable running : bool;
	 }

let create () = { start_time = 0.0;
		  stop_time = 0.0;
		  running = false;
		}

let start timer = 
  if timer.running then failwith "Timer started twice in a row."
  else ( timer.start_time <- Unix.gettimeofday ();
	 timer.running <- true )

let stop timer = 
  if not timer.running then failwith "Timer stopped when not running."
  else ( timer.stop_time <- Unix.gettimeofday ();
	 timer.running <- false )

let read timer = 
  if timer.running 
  then failwith "Timer read at wrong time"
  else timer.stop_time -. timer.start_time

let read_ms timer = 1000.0 *. (read timer)
let read_us timer = (1000.0 *. 1000.0) *. (read timer)