1. camlspotter
  2. spotlib

Commits

camlspotter  committed 2669d0b

incompatibility: Xunix.shell_command and Xunix.command have no longer ~f label

  • Participants
  • Parent commits 6dc5506
  • Branches default

Comments (0)

Files changed (2)

File lib/xunix.ml

View file
  • Ignore whitespace
   with Unix_error (EINTR, _, _) -> waitpid_non_intr pid
 ;;
     
-let command_wrapper (pid, (out, in_, err)) ~f =
+let command_wrapper (pid, (out, in_, err)) f =
   try
     close in_;
     set_nonblock out;
 let shell_command cmd = command_wrapper (open_shell_process_full cmd)
 
 let cmp p1 p2 = 
-  match command ["cmp"; p1; p2] ~f:ignore with
+  match command ["cmp"; p1; p2] ignore with
   | Unix.WEXITED 0 -> `Same
   | Unix.WEXITED 1 -> `Different
   | Unix.WEXITED 2 -> `Error
   | _ -> `Error (* something extremely wrong happened *)
+
+let gen_timed get minus f v = 
+  let t1 = get () in
+  let res = f v  in
+  let t2 = get () in
+  res, minus t2 t1
+
+let timed f v = gen_timed Unix.gettimeofday (-.) f v
+
+module Process_times = struct
+  type t = process_times
+  let (-) pt1 pt2 = {
+    tms_utime = pt1.tms_utime  -. pt2.tms_utime;
+    tms_stime = pt1.tms_stime  -. pt2.tms_stime;
+    tms_cutime = pt1.tms_utime -. pt2.tms_cutime;
+    tms_cstime = pt1.tms_utime -. pt2.tms_cstime;
+  }
+  let timed f v = gen_timed Unix.times (-) f v
+end

File lib/xunix.mli

View file
  • Ignore whitespace
 
 val shell_command :
   string 
-  -> f: ([> `Out | `Err] * [ `Read of string | `EOF ] -> unit) 
+  -> ([> `Out | `Err] * [ `Read of string | `EOF ] -> unit) 
   -> Unix.process_status
 (** Execute a shell command using /bin/sh *)
 
 val command :
   string list
-  -> f: ([> `Out | `Err] * [ `Read of string | `EOF ] -> unit) 
+  -> ([> `Out | `Err] * [ `Read of string | `EOF ] -> unit) 
   -> Unix.process_status
 (** Same as [shell_command] but it takes the command and arguments as a list of string,
     then directly executed by [Unix.execvp]. *)
 
 val cmp : string -> string -> [`Same | `Different | `Error]
 (** Execute "cmp", the file comparison unix command by execvp *)
+  
+val gen_timed : (unit -> 't) -> ('t -> 't -> 't) -> ('a -> 'b) -> 'a -> 'b * 't
+
+val timed : ('a -> 'b) -> 'a -> 'b * float
+
+module Process_times : sig
+  type t = process_times
+  val (-) : t -> t -> t
+  val timed : ('a -> 'b) -> 'a -> 'b * t
+end
+