src/Pure/ML-Systems/cpu-timer-gc.ML
changeset 14519 4ca3608fdf4f
child 14979 245955f0c579
equal deleted inserted replaced
14518:c3019a66180f 14519:4ca3608fdf4f
       
     1 (*  Title:      Pure/ML-Systems/cpu-timer-gc.ML
       
     2     ID:         $Id$
       
     3     Author:     Sebastian Skalberg (TU Muenchen)
       
     4 
       
     5 Implementation of timing functions, building on implementations where
       
     6 the return type of Timer.checkCPUTimer includes a gc field.
       
     7 *)
       
     8 
       
     9 (*Note start point for timing*)
       
    10 fun startTiming() =
       
    11   let val CPUtimer = Timer.startCPUTimer();
       
    12       val time = Timer.checkCPUTimer(CPUtimer)
       
    13   in  (CPUtimer,time)  end;
       
    14 
       
    15 (*Finish timing and return string*)
       
    16 fun endTiming (CPUtimer, {gc,sys,usr}) =
       
    17   let open Time  (*...for Time.toString, Time.+ and Time.- *)
       
    18       val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
       
    19   in  "User " ^ toString (usr2-usr) ^
       
    20       "  GC " ^ toString (gc2-gc) ^
       
    21       "  All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
       
    22       " secs"
       
    23       handle Time => ""
       
    24   end;
       
    25