aboutsummaryrefslogtreecommitdiff
path: root/src/nbc/stopwatch.sml
diff options
context:
space:
mode:
Diffstat (limited to 'src/nbc/stopwatch.sml')
-rw-r--r--src/nbc/stopwatch.sml24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/nbc/stopwatch.sml b/src/nbc/stopwatch.sml
new file mode 100644
index 0000000..43547ed
--- /dev/null
+++ b/src/nbc/stopwatch.sml
@@ -0,0 +1,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