blob: 43547ed3ab3f01c89e60b693fc9cbee8181ce048 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
signature STOPWATCH = sig
exception FinishWithoutStart
val start: string -> unit
val finish: unit -> unit
end
structure Stopwatch :> STOPWATCH = struct
exception FinishWithoutStart
local
val time = ref NONE
in
fun start doing = (
print (concat [doing, "..."])
; time := SOME (Time.now ())
)
fun finish () = case !time of
SOME t => (
print (concat [
" done in "
, Time.toString (Time.- (Time.now (), t))
, " seconds.\n"
]); time := NONE
) | NONE => raise FinishWithoutStart
end
end
|