(* To time a function (f: unit -> 'a), execute timeit f. The output is time spent in user mode, time spent in system mode, and time spent garbage collecting. Add the three to get an honest total time. All times are in seconds. *) fun timeit (f:unit ->'a) = let open Timer Time val cputimer = startCPUTimer() and realtimer = startRealTimer() val result = f() val realtime = checkRealTimer realtimer val cputimes = checkCPUTimer cputimer in print "u "; print (toString (#usr cputimes)); print "\t"; print "s "; print (toString (#sys cputimes)); print "\t"; print "gc "; print (toString (#gc cputimes)); print "\t"; print "r "; print (toString realtime); print "\n"; result end