pdf-report.lisp 10.1 KB
Newer Older
Eric Marsden's avatar
Eric Marsden committed
1
2
3
;;; pdf-report.lisp
;;
;; Author: Eric Marsden <emarsden@laas.fr>
4
;; Time-stamp: <2016-05-13 12:24:31 jack>
Eric Marsden's avatar
Eric Marsden committed
5
6
7
8
;;
;;
;; When loaded into CMUCL, this should generate a report comparing the
;; performance of the different CL implementations which have been
9
;; tested. Reads the output/CL-benchmark* files to obtain data from
Eric Marsden's avatar
Eric Marsden committed
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
;; previous runs. Requires the cl-pdf library. 

(in-package :cl-user)

(eval-when (:load-toplevel :execute)
  (require :asdf)
  (asdf:oos 'asdf:load-op :uffi)
  (ext:load-foreign "/usr/lib/libz.so")
  (asdf:oos 'asdf:load-op :cl-pdf)
  (asdf:oos 'asdf:load-op :cl-typesetting))

(load #p"defpackage.lisp")
(load #p"support.lisp")
(load #p"tests.lisp")


(in-package :cl-bench)


(defun histogram-maker (title label-names results)
  (lambda (box x y)
    (pdf:in-text-mode
     (pdf:move-text x y)
     (pdf:set-font (pdf:get-font "Helvetica") 11)
     (pdf:show-text title))
    (pdf:draw-object
     (make-instance 'pdf:histogram
                    :x x :y (- y 95)
                    :width 90 :height 90
                    :label-names label-names
                    :labels&colors '(("ignore" (0.0 0.0 1.0)))
                    :series (list results)
                    :y-axis-options '(:min-value -0.5 :title "seconds")
                    :background-color '(0.9 0.9 0.9)))))



;; FIXME annotate each benchmark with estimated allocation volume & peak storage requirement
48
(defun bench-analysis (&optional (filename #p"bench:result;cl-bench.pdf"))
Eric Marsden's avatar
Eric Marsden committed
49
  (let (content data groups implementations benchmarks impl-scores impl-labels)
50
    (dolist (f (directory "bench:result;CL-benchmark*.*"))
Eric Marsden's avatar
Eric Marsden committed
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
      (ignore-errors
        (with-open-file (f f :direction :input)
          (let ((*read-eval* nil))
            (push (read f) data)))))
    (setf data (sort data #'string< :key #'car))
    (setf implementations (mapcar #'car data))
    (loop :for b :in *benchmarks*
          :do (pushnew (benchmark-group b) groups))
    (setf impl-scores (make-list (length implementations)
				 :initial-element 0))
    (setf impl-labels (loop :for i :from 0 :below (length implementations)
                            :collect (string (code-char (+ i (char-code #\A))))))
    (setf benchmarks (reverse (mapcar #'first (cdr (first data)))))

    (let ((*break-on-signals* 'condition)
          (header (typeset::compile-text ()
                     (typeset::paragraph (:h-align :centered
                                          :font "Times-Italic" :font-size 10)
                      "cl-bench performance benchmarks")
                    (typeset:hrule :dy 1/2)))
          (footer (lambda (pdf:*page*)
                    (typeset::compile-text (:font "Helvetica" :font-size 9)
                      (typeset:hrule :dy 1/2)
                      (typeset::hbox (:align :center :adjustable-p t)
                        (typeset::put-string "2004-03-09")
                        :hfill
                        (typeset::put-string
                         (format nil "page ~d"
                                 (1+ (position pdf:*page* (typeset::pages pdf:*document*))))))))))    
    (typeset::with-document (:author "ric Marsden"
                             :title "cl-bench performance results")
      (dolist (group groups)
          (setq content
                (typeset::compile-text (:first-line-indent 0)
                  (typeset:paragraph (:font "Times-Italic" :font-size 16)
                     (typeset:put-string (concatenate 'string (string group) " group")))
                  (typeset::vspace 10)
                  (typeset:hrule :dy 1)
                  (typeset::vspace 40)
                  (typeset::paragraph (:first-line-indent 0)
                  (dolist (bm (remove-if-not (lambda (b) (eql (benchmark-group b) group)) *benchmarks*))
                    (let* ((bn (benchmark-name bm))
                           (results (loop :for i :in implementations
                                          :collect (let* ((id (cdr (assoc i data :test #'string=)))
                                                          (ir (third (assoc bn id :test #'string=))))
                                                     (if (numberp ir) (float ir) -0.02)))))
                      ;; (typeset::hspace 10)
                      (typeset::user-drawn-box
                       :inline t :dx 130 :dy 150
                       :stroke-fn (histogram-maker bn impl-labels results))
                      (typeset::hspace 20)))
                  :eop)))
          (typeset::draw-pages content :margins '(72 72 72 72) :header nil :footer footer))
      (setq content
            ;; index of implementation names
            (typeset::compile-text (:first-line-indent 0)
                (typeset::paragraph (:font-size 16) "Implementations")
                (typeset::vspace 10)
                (typeset::hrule :dy 1)
                (typeset::vspace 10)
                (dotimes (i (length implementations))
                 (typeset::paragraph (:font "Times-Roman" :font-size 12)
                   (typeset::put-string (format nil "~A: ~A~%~%" (nth i impl-labels) (nth i implementations))))
                  :eol)
                :eop :eop))
      (typeset::draw-pages content :margins '(72 72 72 72) :header nil :footer footer)
      (pdf:write-document filename)))))



121
;; (defun bench-analysis (&optional (filename #p"bench:result;cl-bench.pdf"))
Eric Marsden's avatar
Eric Marsden committed
122
;;   (let (data groups implementations benchmarks impl-scores impl-labels)
123
;;     (dolist (f (directory "bench:result;CL-benchmark*.*"))
Eric Marsden's avatar
Eric Marsden committed
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
;;       (ignore-errors
;;         (with-open-file (f f :direction :input)
;;           (let ((*read-eval* nil))
;;             (push (read f) data)))))
;;     (setf data (sort data #'string< :key #'car))
;;     (setf implementations (mapcar #'car data))
;;     (loop :for b :in *benchmarks*
;;           :do (pushnew (benchmark-group b) groups))
;;     (setf impl-scores (make-list (length implementations)
;; 				 :initial-element 0))
;;     (setf impl-labels (loop :for i :from 0 :below (length implementations)
;;                             :collect (string (code-char (+ i (char-code #\A))))))
;;     (setf benchmarks (reverse (mapcar #'first (cdr (first data)))))
;; 
;;     ;; FIXME possibly group graphs one group per page
;;     ;;
;;     ;; add numbers on bars
;;     ;;
;;     ;; annotate each benchmark with estimated allocation volume & peak storage requirement
;;     (pdf:with-document (:author "ric Marsden"
;;                         :title "cl-bench performance results")
;;       (let ((helvetica (pdf:get-font "Helvetica"))
;;             (helvetica-bold (pdf:get-font "Helvetica-Bold"))
;;             (helvetica-oblique (pdf:get-font "Helvetica-Oblique"))
;;             (times (pdf:get-font "Times-Roman"))
;;             (page 0)
;;             (per-page 0)
;;             (page-name ""))
;;         (dolist (group groups)
;;           (incf page)
;;           (setf page-name (format nil "page ~d" page))
;;           (pdf:with-page ()
;;             (pdf:register-page-reference page-name)
;;             (pdf:with-outline-level (group page-name)
;;               ;; group name
;;               (pdf:in-text-mode
;;                (pdf:set-font helvetica-bold 16.0)
;;                (pdf:move-text 100 700)
;;                (pdf:draw-text (string group)))
;;               ;; version number
;;               (pdf:in-text-mode
;;                (pdf:set-font helvetica-oblique 8)
;;                (pdf:move-text 10 10)
;;                (pdf:draw-text (format nil "cl-bench version ~A" *version*)))
;;               (setf per-page 1)
;;               (dolist (bm (remove-if-not (lambda (b) (eql (benchmark-group b) group)) *benchmarks*))
;;                 (format *debug-io* "Group ~A, benchmark ~A~%" group bm)
;;                 (let* ((bn (benchmark-name bm))
;;                        (results (loop :for i :in implementations
;;                                       :collect (let* ((id (cdr (assoc i data :test #'string=)))
;;                                                       (ir (third (assoc bn id :test #'string=))))
;;                                                  (if (numberp ir) (float ir) -0.02))))
;;                        (ypos (- 640 (* 150 per-page))))
;;                   ;; with-column-layout
;;                   ;; test title
;;                   (incf per-page)
;;                   `(pdf:in-text-mode
;;                     (pdf:set-font helvetica-bold 16.0)
;;                     (pdf:move-text 100 ,ypos)
;;                     (pdf:draw-text bn))
;;                   ;; optional extra description
;; ;;                   (when (and b (benchmark-long b))
;; ;;                     (pdf:in-text-mode
;; ;;                      (pdf:set-font helvetica 12)
;; ;;                      (pdf:move-text 100 520)
;; ;;                      (pdf:draw-text (benchmark-long b))))
;;                   ;; y-axis title
;; ;;                   (pdf:with-saved-state
;; ;;                       (pdf:translate 65 350)
;; ;;                     (pdf:rotate 90)
;; ;;                     (pdf:in-text-mode
;; ;;                      (pdf:set-font helvetica 10)
;; ;;                      (pdf:draw-text "seconds")))
;;                   (pdf:draw-object
;;                    (make-instance 'pdf:histogram
;;                                   :x 100 :y ypos
;;                                   :width 100 :height 100
;;                                   :label-names impl-labels
;;                                   :labels&colors '(("ignore" (0.0 0.0 1.0)))
;;                                   :series (list results)
;;                                   :y-axis-options '(:min-value -0.5 :title "seconds")
;;                                   :background-color '(0.9 0.9 0.9)))
;;                   #+nil
;;                   (pdf:in-text-mode
;;                    (pdf:move-text 100 250)
;;                    (pdf:set-font times 12.0)
;;                    (dotimes (i (length implementations))
;;                      (pdf:move-text 0 -14)
;;                      (pdf:draw-text (format nil "~A: ~A"
;;                                             (nth i impl-labels)
;;                                             (nth i implementations)))))))))))
;;       (pdf:write-document filename))))


(bench-analysis)
(quit)

;; EOF