html-report.lisp 13.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
;;; html-report.lisp
;;; 
;;; Time-stamp: <2016-05-20 14:36:27 jack>
;;; 
;;; Inspired by a benchmark page example from lispm.de kindly shared
;;; by Rainer Joswig
;;;
;;; * Copyright (c) 2016 Rainer Joswig <joswig@lisp.de>
;;; * Copyright (c) 2016 Daniel Kochmański <daniel@turtleware.eu>
;;; 

(in-package #:cl-bench)

(defun read-benchmarks ()
  (let (data)
    (dolist (f (directory (merge-pathnames "CL-benchmark*.*" *output-dir*)) data)
      (with-open-file (f f :direction :input)
        (let ((*read-eval* nil))
          (push (read f) data))))))

(defun bench-analysis-page ()
  (let* ((data (read-benchmarks))
         (implementations (mapcar #'car data))
         (benchmarks (reverse (mapcar #'first (cdr (first data))))))
    (with-open-file (s #P"/tmp/bench.html" :direction :output :if-exists :supersede)
      (cl-who:with-html-output (s nil :prologue t)
        (cl-who:htm
         (:p "hello world!")
         (:table
          :border 1
          (:tr (:td :style "max-width: 100px;")
               (dolist (i implementations)
                 (cl-who:htm (:th (cl-who:str i)))))
          (dolist (b benchmarks)
            (let* ((results (loop :for i in implementations
                               :collect (let* ((id (cdr (assoc i data :test #'string=)))
                                               (ir (third (assoc b id :test #'string=))))
                                          (if (numberp ir)
                                              ir
                                              -1))))
                   (best (apply #'min results)))
              (cl-who:htm
              (:tr (:th (cl-who:str b))
                   (dolist (r results)
                     (flet ((cell-color (value best)
                                    (cond ((> value (* 4 best)) "#b4b")
                                          ((> value (* 2 best)) :red)
                                          ((> value (* 1.6 best)) :orange)
                                          ((> value (* 1.25 best)) "#4b4")
                                          ((<= value (* 1.25 best)) :green)))
                            (cell-style (color)
                              (format nil "background-color: ~A;" color)))
                       (cl-who:htm (:td :style (cell-style (cell-color r best))
                                        (cl-who:str r)))
                       )))
              )))))))
    benchmarks))

(defun render-benchmark-table (values stream &key (table-type :vertical))
  (labels ((br (&optional (n 1))
             (loop repeat n do (html2:break-line :stream stream)))
           (cell (value stream &key header-p color (horizontal-alignment :left))
             (netscape4.0:with-table-cell (:stream stream
                                           :background color
                                           :header-p header-p
                                           :horizontal-alignment horizontal-alignment)
               (html3.2:with-rendition (:small :stream stream)
                 (princ value stream))))
           (render-legend ()
             (html3.2:with-rendition (:small :stream stream)
               (princ "Legend " stream))
             (html4.0:with-table (:stream stream :border 0)
               (html3.2:with-table-row (:stream stream)
                 (loop for (color description) in '((:green "very fast")
                                                    (:green-yellow "fast")
                                                    (:orange "slow")
                                                    (:red-orange "very slow")
                                                    (:red-violet "extremely slow"))
                       do (cell description stream :color color)))))
           (render-table (values)
             (html4.0:with-table (:stream stream :border 0)
               (html3.2:with-table-row (:stream stream)
                 (loop for item in (first values)
                       do (cell item stream :header-p t :horizontal-alignment :center)))
               (loop for (name . row-values) in (rest values)
                     do  (html3.2:with-table-row (:stream stream)
                           (cell name stream :header-p t :horizontal-alignment :right)
                           (flet ((cell-color (value best)
                                    (cond ((> value (* 4 best)) :red-violet)
                                          ((> value (* 2 best)) :red-orange)
                                          ((> value (* 1.6 best)) :orange)
                                          ((> value (* 1.25 best)) :green-yellow)
                                          ((<= value (* 1.25 best)) :green))))
                             (loop with best = (reduce 'min (remove-if-not #'numberp row-values))
                                   for value in row-values
                                   for color = (and value (cell-color value best))
                                   do (if color
                                          (cell value stream :color color)
                                        (cell (if (numberp value) value "no value") stream))))))))
           (render-remarks ()
             (html3.2:with-rendition (:small :stream stream)
               (princ *benchmark-comments* stream)))
           (render-tables-1 ()
             (princ "Mac OS X 10.2.6/8, Apple Powerbook G4, 800 Mhz, 1 GB RAM, 20. August 2003" stream)
             (br 2)
             (html4.0:with-table (:stream stream :border 0)
               (html3.2:with-table-row (:stream stream)
                 (html3.2:with-table-cell (:stream stream)
                   (princ "full optimizations" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "no optimizations" stream)))
               (html3.2:with-table-row (:stream stream)
                 (html3.2:with-table-cell (:stream stream)
                   (render-table (first values)))
                 (html3.2:with-table-cell (:stream stream)
                   (render-table (second values)))))
             (br 2)
             (princ "Mac OS X 10.3, Apple Powerbook G4, 1.33 Ghz, 1 GB RAM, 3. November 2003" stream)
             (br 2)
             (render-table (third values))
             (br))
           (render-tables-2 ()
             (br 2)
             (html4.0:with-table (:stream stream :border 0)
               (html3.2:with-table-row (:stream stream)
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Ubuntu GNU Linux, ODROID XU, 1.6 Ghz ARM Cortex-A15,<br>2 GB RAM, 20. November 2015, full optimizations" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Ubuntu GNU Linux, ODROID-U3, 1.7 Ghz ARM Cortex-A9,<br>2 GB RAM, 6. June 2015, full optimizations" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.9, Apple Mac mini 2012, 2.6 Ghz Intel Core i7,<br>16 GB RAM, 4. October 2013, full optimizations" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Ubuntu GNU Linux, ODROID-XU, 1.6 Ghz ARM Cortex-A15,<br>2 GB RAM, 3. October 2013, full optimizations" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.6.2, Apple MacBook Pro, Intel Core 2 Duo 2.33 Ghz,<br>24. Jan 2010, full optimizations" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.4.9, Apple MacBook Pro, Intel Core 2 Duo 2.33 Ghz,<br>6. March 2007" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.4.6, Apple MacBook, Intel Core Duo 1.83 Ghz,<br>28. May 2006" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.3.5, Apple PowerMac G5, Dual 2.5 Ghz,<br>19. October 2004" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.2.8, Apple PowerMac G5, Dual 2 Ghz,<br>15. November 2003" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.3, Apple Powerbook G4, 1.33 Ghz,<br> 1 GB RAM, 3. November 2003" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.2.6/8, Apple Powerbook G4, 800 Mhz,<br> 1 GB RAM, 20. August 2003, full optimizations" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.2.6/8, Apple Powerbook G4, 800 Mhz,<br>1 GB RAM, 20. August 2003, no optimizations" stream))
                 )
               (html3.2:with-table-row (:stream stream)
                 (loop for i from 11 downto 0
                       do (html3.2:with-table-cell (:stream stream)
                            (render-table (elt values i))))))
             (br))
           (render-tables-3 ()
             (br 2)
             (html4.0:with-table (:stream stream :border 0)
               (html3.2:with-table-row (:stream stream)
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.4.9, Apple MacBook Pro, Intel Core 2 Duo 2.33 Ghz,<br> March 2007" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.4.6, Apple MacBook, Intel Core Duo 1.83 Ghz,<br> 28. May 2006" stream))
                 (html3.2:with-table-cell (:stream stream)
                   (princ "Mac OS X 10.4.6, Apple PowerMac G5, PowerPC 970fx 2*2.5 Ghz,<br> 28. May 2006" stream)))
               (html3.2:with-table-row (:stream stream)
                 (html3.2:with-table-cell (:stream stream)
                   (render-table (first values)))
                 (html3.2:with-table-cell (:stream stream)
                   (render-table (second values)))
                 (html3.2:with-table-cell (:stream stream)
                   (render-table (third values)))))
             (br)))
    (with-paragraph (:stream stream
                     :title "Benchmarks for some Lisps under Mac OS X")
      (br 1)
      (html3.2:with-rendition (:small :stream stream)
        (princ "The " stream) 
        (html2:note-anchor "benchmark code" :reference "http://www.chez.com/emarsden/downloads/"
                           :stream stream)
        (princ " is from Eric Marsden, based on the Gabriel Benchmarks." stream))
      (br 2)
      (render-legend)
      (br 2)
      (ecase table-type
        (:vertical (render-tables-1))
        (:horizontal (render-tables-2))
        (:hidden (render-tables-3)))
      (render-remarks))))


(defun generate-benchmark-page (url stream)
  (generate-basic-page
   url stream
   :render-function (lambda (url stream)
                      (declare (ignore url))
                      (render-benchmark-table
                       (list *benchmark1-values* *benchmark-values* *benchmark2-values*
                             *benchmark3-values* *benchmark4-values* *benchmark5-values*
                             *benchmark8-values* *benchmark9-values* *benchmark10-values*
                             *benchmark11-values* *benchmark13-values* *benchmark14-values*)
                       stream
                       :table-type :horizontal))
   :title "Rainer Joswig's Home, Lisp Benchmarks"))


(defparameter *benchmark14-values*
'(("Benchmark" "SBCL 1.3.0" "CCL 1.11" "LispWorks 7" "GCL 2.6.12" "ECL 16.0.0" "ABCL 1.3.3" "CLISP 2.49")
 (BOYER 0.565 0.61 1.645 0.96 1.785 1.556 5.595)
 (BROWSE 0.23 0.245 0.225 0.61 0.545 0.723 1.205)
 (DDERVIV 0.27 0.145 0.24 0.43 1.33 0.788 1.625)
 (DERIV 0.295 0.255 0.455 0.75 2.455 1.498 2.915)
 (DESTRUCTIVE 0.43 0.33 0.26 0.35 0.935 2.188 2.47)
 (DIV2-TEST-1 0.22 0.18 0.335 0.47 1.59 1.014 2.375)
 (DIV2-TEST-2 0.115 0.095 0.17 0.2 0.83 0.496 1.195)
 (FFT 0.085 0.075 0.2 2.94 0.105 0.75 5.625)
 (FRPOLY/FIXNUM 0.35 0.2 0.405 0.52 0.75 1.282 3.195)
 (FRPOLY/BIGNUM 0.655 0.465 1.13 1.16 0.815 1.104 2.8)
 (FRPOLY/FLOAT 0.245 0.305 0.355 0.26 0.54 0.718 2.075)
 (PUZZLE 0.125 0.39 0.225 1.21 0.675 2.045 4.225)
 (CTAK 0.615 0.79 0.7 1.43 1.88 10.475 4.64)
 (TAK 0.425 0.285 0.36 0.88 0.67 0.791 5.355)
 (RTAK 0.425 0.29 0.36 0.89 0.67 0.581 5.355)
 (TAKL 0.61 0.725 0.69 0.63 0.67 0.975 7.66)
 (STAK 0.815 0.925 0.7 0.58 1.18 11.266 5.08)
 (FPRINT 4.315 1.25 0.435 0.36 0.98 1.553 0.32)
 (TRAVERSE 0.9 1.025 1.055 1.45 5.825 3.017 11.21)
 (TRIANGLE 0.9 1.085 1.03 1.79 2.24 3.181 20.14)
 (CASCOR 0.74 2.685 NIL NIL 1.15 10.915 48.125)
 (RICHARDS 0.37 0.565 0.605 0.36 3.375 1.892 6.09)
 (FACTORIAL 0.13 0.055 0.215 0.35 0.185 0.314 0.525)
 (FIB 0.305 0.05 0.07 0.12 0.31 0.137 1.02)
 (BIGNUM/ELEM-100-1000 0.305 0.675 0.545 0.69 0.095 1.117 0.07)
 (BIGNUM/ELEM-1000-100 0.69 3.35 0.94 1.48 0.11 0.889 0.24)
 (BIGNUM/ELEM-10000-1 0.82 5.015 0.87 0.88 0.14 0.573 0.21)
 (BIGNUM/PARI-100-10 0.055 0.655 0.06 0.02 0.015 0.207 0.045)
 (BIGNUM/PARI-200-5 0.195 7.965 0.195 0.07 0.075 0.411 0.14)
 (HASH-STRINGS 0.05 0.115 0.04 0.23 0.07 0.587 0.165)
 (HASH-INTEGERS 0.13 0.35 0.175 0.2 0.245 0.841 0.535)
 (BOEHM-GC 2.97 2.52 1.76 6.56 8.76 14.225 15.645)
 (CLOS/DEFCLASS 1.74 0.395 0.245 NIL 0.425 7.314 0.805)
 (CLOS/DEFMETHOD 3.91 0.145 0.195 NIL 0.285 3.974 0.23)
 (CLOS/INSTANTIATE 2.445 2.1 1.3 NIL 6.205 15.559 2.135)
 (CLOS/METHODCALLS 15.765 2.575 4.255 NIL 3.835 29.736 6.625)
 (CLOS/METHOD+AFTER 3.365 1.595 2.145 NIL 2.49 20.839 4.34)
 (CLOS/COMPLEX-METHODS 2.42 0.915 0.505 NIL 53.965 20.42 NIL)
 (1D-ARRAYS 0.645 0.255 0.355 1.46 0.8 0.888 4.4)
 (2D-ARRAYS 0.575 0.415 0.245 1.29 0.49 4.069 5.91)
 (BITVECTORS 0.28 0.05 0.07 0.3 0.92 0.205 0.515)
 (FILL-STRINGS 0.24 0.175 0.405 0.99 0.435 2.296 1.195)
 (FILL-STRINGS/ADJUSTABLE 0.145 0.135 0.195 0.02 0.035 0.179 0.385)))