let profile str f a =
if !profiling then
let timer = ref 0. in
let calls = ref 0 in
add_at_exit
(fun () -> Format.printf "%s: utime = %f calls = %d\n@ " str !timer !calls);
(fun x ->
let start = (Unix.times()).tms_utime in
let y = f x in
let finish = (Unix.times()).tms_utime in
timer := !timer +. (finish -. start);
calls := !calls + 1;
y) a
else
f a