src/Pure/ML-Systems/smlnj-0.93.ML
changeset 4506 f21ec26b2265
parent 4494 7e5611945959
child 4977 6cec2c0ffdbf
equal deleted inserted replaced
4505:4a2c872b6513 4506:f21ec26b2265
    25 fun print_depth n =
    25 fun print_depth n =
    26  (System.Control.Print.printDepth := n div 2;
    26  (System.Control.Print.printDepth := n div 2;
    27   System.Control.Print.printLength := n);
    27   System.Control.Print.printLength := n);
    28 
    28 
    29 
    29 
       
    30 
    30 (* timing *)
    31 (* timing *)
    31 
    32 
       
    33 (*Note start point for timing*)
       
    34 fun startTiming() = System.Timer.start_timer();
       
    35 
       
    36 (*Finish timing and return string*)
    32 local
    37 local
    33   (*print microseconds, suppressing trailing zeroes*)
    38   (*print microseconds, suppressing trailing zeroes*)
    34   fun umakestring 0 = ""
    39   fun umakestring 0 = ""
    35     | umakestring n =
    40     | umakestring n =
    36         chr (ord "0" + n div 100000) ^ umakestring (10 * (n mod 100000));
    41         chr (ord "0" + n div 100000) ^ umakestring (10 * (n mod 100000));
       
    42 
       
    43   fun string_of_time (System.Timer.TIME {sec, usec}) =
       
    44       makestring sec ^ "." ^ (if usec=0 then "0" else umakestring usec)
       
    45 
    37 in
    46 in
    38   (*a conditional timing function: applies f to () and, if the flag is true,
    47 
    39     prints its runtime*)
    48 fun endTiming start =
    40   fun cond_timeit flag f =
    49   let val nongc = System.Timer.check_timer(start)
    41     if flag then
    50       and gc    = System.Timer.check_timer_gc(start);
    42       let fun string_of_time (System.Timer.TIME {sec, usec}) =
    51       val both  = System.Timer.add_time(nongc, gc)
    43               makestring sec ^ "." ^ (if usec=0 then "0" else umakestring usec)
    52   in  "Non GC " ^ string_of_time nongc ^
    44           open System.Timer;
    53       "   GC " ^ string_of_time gc ^
    45           val start = start_timer()
    54       "  both "^ string_of_time both ^ " secs\n"
    46           val result = f();
    55   end
    47           val nongc = check_timer(start)
       
    48           and gc = check_timer_gc(start);
       
    49           val both = add_time(nongc, gc)
       
    50       in  print("Non GC " ^ string_of_time nongc ^
       
    51                  "   GC " ^ string_of_time gc ^
       
    52                  "  both "^ string_of_time both ^ " secs\n");
       
    53           result
       
    54       end
       
    55     else f();
       
    56 end;
    56 end;
       
    57 
       
    58 
    57 
    59 
    58 
    60 
    59 (* toplevel pretty printing (see also Pure/install_pp.ML) *)
    61 (* toplevel pretty printing (see also Pure/install_pp.ML) *)
    60 
    62 
    61 fun make_pp path pprint =
    63 fun make_pp path pprint =