Commits

camlspotter  committed 5eabc67

Base.with_time

  • Participants
  • Parent commits 698ecc6

Comments (0)

Files changed (4)

 name="spotlib"
 version="0.0.1"
 description="Spotter's garbages"
-requires=""
+requires="unix"
 archive(byte)="spotlib.cmo"
 archive(native)="spotlib.cmx"
 linkopts = ""
 # CAMLP4PACKS[]=
 #     sexplib
 # 
-# OCAMLPACKS[]= 
-#     sexplib
+OCAMLPACKS[]= unix
+
 # 
 # OCAMLDEPFLAGS= -syntax camlp4o -package sexplib.syntax
 # OCAMLPPFLAGS= -syntax camlp4o -package sexplib.syntax
   | `Ok v -> finally (); v
   | `Exn e -> finally (); raise e
 
-    
+let with_time f v =
+  let open Unix in 
+  let start = Unix.times () in
+  let res = f v in
+  let end_ = Unix.times () in
+  res, { tms_utime  = end_.tms_utime  -. start.tms_utime;
+         tms_stime  = end_.tms_stime  -. start.tms_stime;
+         tms_cutime = end_.tms_cutime -. start.tms_cutime;
+         tms_cstime = end_.tms_cstime -. start.tms_cstime; }
   (** Haskell's ($) *)
 
 val protect : ('a -> 'b) -> 'a -> finally: (unit -> unit) -> 'b
+
+val with_time : ('a -> 'b) -> 'a -> 'b * Unix.process_times
+  (** simple profiling *)
+