Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/benchmarks/programs/timeit.sml
ViewVC logotype

Annotation of /sml/trunk/benchmarks/programs/timeit.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 193 - (view) (download)

1 : monnier 193 signature BMARK =
2 :     sig
3 :     val doit : unit -> unit
4 :     val testit : TextIO.outstream -> unit
5 :     end;
6 :    
7 :     structure Timing = struct
8 :     structure TR = Timer
9 :     structure T = Time
10 :     type timing = {usr:T.time, gc:T.time, sys:T.time, real:T.time}
11 :     val pad10 = " "
12 :     fun pad (s, n) = let
13 :     val l = size s
14 :     in
15 :     if (n <= l)
16 :     then s
17 :     else if ((n-l) >= 10)
18 :     then pad (pad10^s, n)
19 :     else substring(pad10, 0, n-l) ^ s
20 :     end
21 :     fun start () =
22 :     (SMLofNJ.Internals.GC.doGC 1000;
23 :     {realt = TR.startRealTimer(), timer = TR.startCPUTimer()})
24 :    
25 :     fun stop {realt, timer} = let
26 :     val rt = TR.checkRealTimer realt
27 :     val {gc, sys, usr} = TR.checkCPUTimer timer
28 :     in {usr=usr, gc=gc, sys=sys, real=rt}
29 :     end
30 :    
31 :     (* convert a time value to a string, padded on the left to 8 characters *)
32 :     fun timeToStr time = pad (Time.toString time, 6)
33 :    
34 :     fun output (strm, {usr, gc, sys, real} : timing) = let
35 :     val str =
36 :     concat[
37 :     "\t{usr = ", timeToStr usr,
38 :     ", sys = ", timeToStr sys,
39 :     ", gc = ", timeToStr gc,
40 :     ", real = ", timeToStr real, "}"
41 :     ]
42 :     in
43 :     TextIO.output (strm, str)
44 :     end
45 :    
46 :    
47 :     (* Time one run of the benchmark *)
48 :     fun timeIt (outstrm, run, doit) = let
49 :     val t0 = start()
50 :     in
51 :     doit();
52 :     output (outstrm, stop t0);
53 :     TextIO.flushOut outstrm
54 :     end
55 :    
56 :     (* Time n runs of the benchmark *)
57 :     fun time (n, outstrm, doit) = let
58 :     fun loop 0 = ()
59 :     | loop 1 = timeIt(outstrm, 1, doit)
60 :     | loop i =
61 :     (timeIt(outstrm, i, doit);
62 :     TextIO.output(outstrm, ",\n");
63 :     loop(i-1))
64 :     in
65 :     TextIO.output(outstrm, " Runs=[\n");
66 :     loop n;
67 :     TextIO.output(outstrm, "\t]")
68 :     end
69 :    
70 :     end
71 :    
72 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0