package lutin

  1. Overview
  2. Docs

Source file utils.ml

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

(**----------------------------------------------------------

            UTILITAIRES

------------------------------------------------------------

----------------------------------------------------------*)

(**********************************************************)


(** iter_sep f s [x1;x2; ...;xn] est équivalent à :

	(f x1); s; (f x2); s; ... ; s; (f xn)
*)
let rec iter_sep f s l = (
   match l with
      [] -> ()
   |  [x] -> (f x)
   |  x::t -> (f x); (s x); iter_sep f s t
)

let _paranoid = ref false
let paranoid () = !_paranoid
let set_paranoid () = (_paranoid := true)

let stat_tab = Hashtbl.create 10

let _prof = ref false
let set_prof () = (_prof := true)

let time_C s = if !_prof then (
		let t = Sys.time () in
		let (n, tot, _lc) = try (
			Hashtbl.find stat_tab s
		) with Not_found -> (0,0.0,0.0)
	in
	Hashtbl.replace stat_tab s (n, tot, t)	
)

let time_R s = if !_prof then (
	let t = Sys.time () in
	let (n, tot, lc) = try (
		Hashtbl.find stat_tab s
	) with Not_found -> (0,0.0,0.0)
	in
	Hashtbl.replace stat_tab s (n+1, tot +. (t -. lc), 0.0)	
)

let time_P () = if !_prof then (
	let pr s (n,tot,_lc) acc = 
		(Printf.sprintf "%-18s %3d  %10.6f\n" s n tot)::acc
	in
	let lines = List.fast_sort compare (Hashtbl.fold pr stat_tab []) in
	List.iter (fun s -> prerr_string s)  lines
)