Debian Codegraph @

benchmarks.larceny/summarize2.sch

raw
1 ; Graphical display of benchmark results.
2 ;
3 ; FIXME: This is awful code.
4
5 ; Given a list of summaries in the representation
6 ; produced by decode-summary, and a filename or
7 ; output port, writes ASCII bar graphs to the file
8 ; or port.
9
10 (define (graph-benchmarks summaries out)
11 (define (bad-arguments)
12 (error "Bad arguments to graph-benchmarks" in))
13 (cond ((string? out)
14 (call-with-output-file
15 out
16 (lambda (out) (graph-benchmarks summaries out))))
17 ((output-port? out)
18 (graph-benchmarks-to-port summaries out))
19 (else
20 (bad-arguments))))
21
22 (define (graph-benchmarks-to-port summaries out)
23 (let* ((results (map summary:timings summaries))
24 (benchmark-names (map timing:benchmark (car results))))
25 (for-each (lambda (name)
26 (graph-benchmark-to-port name summaries out))
27 benchmark-names)))
28
29 (define width:system 8)
30 (define width:timing 8)
31 (define width:gap 2)
32 (define width:bar 60)
33 (define width:total (+ width:system width:timing width:gap width:bar))
34
35 (define anchor1 "<a href=\"LINK.html#")
36 (define anchor2 "\">")
37 (define anchor3 "</a>")
38
39 (define (graph-benchmark-to-port name summaries out)
40
41 ; Strips -r6rs-fixflo and similar suffixes from system names.
42
43 (define (short-name system)
44 (let* ((rchars (reverse (string->list system)))
45 (probe (memv #\- rchars)))
46 (if probe
47 (short-name (list->string (reverse (cdr probe))))
48 system)))
49
50 (display (make-string (- width:total (string-length (symbol->string name)))
51 #\space)
52 out)
53 (display anchor1 out)
54 (display name out)
55 (display anchor2 out)
56 (display name out)
57 (display anchor3 out)
58 (newline out)
59
60 (let* ((systems (map summary:system summaries))
61 (systems (map short-name systems))
62 (results (map summary:timings summaries))
63 (timings (map (lambda (x) (assq name x))
64 results))
65 (best (apply min
66 (map timing:real
67 (filter (lambda (x) x) timings)))))
68 (for-each (lambda (system timing)
69 (if (list? timing)
70 (graph-system system (timing:real timing) best out)
71 (graph-system system 0 best out)))
72 systems
73 timings)))
74
75 (define graph-system:args '())
76 (define graph-system:bar1 "<span style=\"background-color:#")
77 (define graph-system:bar2 "\">")
78 (define graph-system:bar3 "</span>")
79
80 (define graph-system:colors
81 '(("Larceny" "800000")
82 ("Bigloo" "000080")
83 ("Chez" "004040")
84 ("Chicken" "a06000")
85 ("Gambit" "400060")
86 ("MIT" "2000c0")
87 ("MzScheme" "008020")
88 ("Petite" "004080")
89 ("Scheme48" "600040")))
90
91 ; Returns a nice color for certain popular systems,
92 ; or returns black.
93
94 (define (system-color system)
95 (let ((probe (assoc system graph-system:colors)))
96 (if probe (cadr probe) "000000")))
97
98
99 (define (graph-system system timing best out)
100 (if (and (number? timing)
101 (positive? timing))
102 (let* ((relative (/ best timing))
103 (color (system-color system)))
104 (left-justify system width:system out)
105 (right-justify (msec->seconds timing) width:timing out)
106 (left-justify "" width:gap out)
107 (display graph-system:bar1 out)
108 (display color out)
109 (display graph-system:bar2 out)
110 (display (make-string (inexact->exact
111 (round (* relative width:bar)))
112 #\space)
113 out)
114 (display graph-system:bar3 out)
115 (newline out))
116 (begin
117 (left-justify system width:system out)
118 (newline out))))
119
120 ; Given a timing in milliseconds,
121 ; returns the timing in seconds,
122 ; as a string rounded to two decimal places.
123
124 (define (msec->seconds t)
125 (let* ((hundredths (inexact->exact (round (/ t 10.0))))
126 (s (number->string hundredths))
127 (n (string-length s)))
128 (cond ((>= n 2)
129 (string-append (substring s 0 (- n 2))
130 "."
131 (substring s (- n 2) n)))
132 (else
133 (string-append ".0" s)))))
134
135 ; Given a summary and a list of summaries,
136 ; returns a list of relative performance (0.0 to 1.0)
137 ; for every benchmark in the summary.
138
139 (define (relative-performance summary summaries)
140
141 (let* ((timings (summary:timings summary))
142 (timings (filter (lambda (t)
143 (let ((realtime (timing:real t)))
144 (and (number? realtime)
145 (positive? realtime))))
146 timings))
147 (other-results (map summary:timings summaries)))
148 (map (lambda (t)
149 (let* ((name (timing:benchmark t))
150 (timings (map (lambda (x) (assq name x))
151 other-results))
152 (best (apply min
153 (map timing:real
154 (filter (lambda (x) x) timings)))))
155 (/ best (timing:real t))))
156 timings)))
157
158 ; Given a list of positive numbers,
159 ; returns its geometric mean.
160
161 (define (geometric-mean xs)
162 (expt (apply * xs) (/ 1 (length xs))))
163
164 ; Given a list of summaries, returns a list of summaries
165 ; augmented by the geometric mean over all benchmarks.
166
167 (define (summaries-with-geometric-means summaries)
168
169 (define name (string->symbol "geometricMean"))
170
171 (map (lambda (summary)
172 (define mean
173 (* 1000
174 (/ (geometric-mean (relative-performance summary summaries)))))
175 (make-summary (summary:system summary)
176 (summary:hostetc summary)
177 (cons
178 (make-timing name mean mean 0)
179 (summary:timings summary))))
180 summaries))