| 1 |
(* timeit.sml |
| 2 |
* 2004 Matthew Fluet ([email protected]) |
| 3 |
* Ported to MLton threads. |
| 4 |
*) |
| 5 |
|
| 6 |
structure TimeIt : TIMEIT = |
| 7 |
struct |
| 8 |
val timeitFlg = true |
| 9 |
|
| 10 |
fun timeit (name: string) (f: 'a -> 'b) (a: 'a) : 'b = |
| 11 |
if timeitFlg |
| 12 |
then let |
| 13 |
val start = Time.now () |
| 14 |
fun done () = |
| 15 |
let |
| 16 |
val finish = Time.now () |
| 17 |
val diff = Time.-(finish, start) |
| 18 |
in |
| 19 |
Debug.sayDebug |
| 20 |
([], fn () => |
| 21 |
concat [name, ": ", |
| 22 |
LargeInt.toString (Time.toMilliseconds diff), |
| 23 |
" ms"]) |
| 24 |
end |
| 25 |
in |
| 26 |
(f a before done ()) |
| 27 |
handle e => (done (); raise e) |
| 28 |
end |
| 29 |
else f a |
| 30 |
end |