Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add fixme, rework slightly *bench* demo
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 7695068fee818f3ef40167dd61dc2370c933f3109eeabd46615964c527a373be
User & Date: jack 2026-05-29 10:37:48
Context
2026-06-23
15:39
cosmetic fixes for cl-bench demo Leaf check-in: c5124687f6 user: jack tags: master, trunk
2026-05-29
10:37
add fixme, rework slightly *bench* demo check-in: 7695068fee user: jack tags: master, trunk
2025-05-12
07:25
fix faceting columns check-in: c572d0ad00 user: jack tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Code/layer.lisp.

︙︙
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83


(define-class <geom-bar> (<layer>)
  (bin-width)
  (:default-initargs :statistical-transformation +stat-count+
                     :bin-width 1/10))


(defmethod render-geom ((g <geom-bar>) (c <coord-cartesian>) dataset)
  (do-aesthetics ((xrange x y ink) dataset)
    (if xrange
        (let ((min (min-pos xrange))
              (max (max-pos xrange))
              (num (print-number y nil)))
          (c:draw-rectangle* t min 0 max y :ink ink)
          (c:draw-text* t num x y :align-x :center :align-y :bottom :text-size :tiny))
        (c:draw-line* t x 0 x y :line-thickness 8 :ink ink))))







>









68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84


(define-class <geom-bar> (<layer>)
  (bin-width)
  (:default-initargs :statistical-transformation +stat-count+
                     :bin-width 1/10))

;;; FIXME y is scaled, so the label is useless(!).
(defmethod render-geom ((g <geom-bar>) (c <coord-cartesian>) dataset)
  (do-aesthetics ((xrange x y ink) dataset)
    (if xrange
        (let ((min (min-pos xrange))
              (max (max-pos xrange))
              (num (print-number y nil)))
          (c:draw-rectangle* t min 0 max y :ink ink)
          (c:draw-text* t num x y :align-x :center :align-y :bottom :text-size :tiny))
        (c:draw-line* t x 0 x y :line-thickness 8 :ink ink))))

Changes to Demo/cl-bench-results.lisp.

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
(in-package "EU.TURTLEWARE.POLYCLOT-USER")


















































































;;; Results of CL-bench are stored in files - one for each implementation -
;;; with a single form inside: (LISP-NAME . RESULTS) where RESULTS is a list
;;; of test cases in a form (TEST-NAME REAL-TIME USER-TIME SYS-TIME CONSED).
;;; If a statistic is not possible to for the implementation to produce, then
;;; it is NIL. For now we will focus on the user time.
;;;
;;; 1. NIL is "not available"
;;; 2. CL aesthetic is "ink"
;;; 3. CL bars are dodged on x axis



(defun read-data (output-dir)
  "Constructs a poor man's data frame."
  (flet ((process-result (form)
           (destructuring-bind (lisp . tests) form
             (loop for i from 0
                   for (test real user sys cons) in tests
                   for batch = (floor i 11)
                   when user            ; FIXME handle gracefully n/a
                     collect (list lisp test user batch)))))
    (cons (list "Lisp" "Test" "Time" "Batch")
          (loop with *read-eval* = nil
                for file in (directory (merge-pathnames "CL-benchmark*.*" output-dir))
                for form = (with-open-file (stream file :direction :input)
                             (read stream))
                append (process-result form)))))

(defun normalize-results (dataset)
  (let ((results (group-by '("Test") dataset))
        (newdata '()))
    (i::dohash ((test test-data) results)
      (when (= 3 (length (rest test-data)))
       (destructuring-bind ((lisp1 test1 time1 batch1)
                            (lisp2 test2 time2 batch2)
                            (lisp0 test0 time0 batch0))
           (rest test-data)
         (assert (and (equalp test1 test2)

                      (equalp test1 test0)))
         (let ((loser (max time0 time1 time2)))
           (push (list lisp0 test (/ time0 loser) batch0) newdata)
           (push (list lisp1 test (/ time1 loser) batch1) newdata)
           (push (list lisp2 test (/ time2 loser) batch2) newdata)))))
    (list* (car dataset) (reverse newdata))))

(defun yah ()
  (let ((dataset (read-data "~/Workshop/Repositories/cl-bench/output/")))
    (normalize-results dataset)))

;;; time1 - 1
;;; time2 - ?

;;; FIXME come up with faceting so that test X is not shared among plots
;;; NCOL doesn't work etc
(defun benches ()
  (let* ((dataset (read-data "~/Workshop/Repositories/cl-bench/output/"))
         (dataset (normalize-results dataset))
         (groups (group-by '("Batch") dataset))
         (plots nil))
    (i::dohash ((batch dataset) groups)
      (declare (ignore batch))
      (push (<polyclot> :title "Common Lisp Benchmark"
                        :width 1280 :height 200
                        :dataset dataset
                        :aesthetics (list :x "Test" :y "Time" :ink "Lisp")
                                        ;:faceting (<faceting-wrap> :var '("Batch") :ncol 1)
                        :layers (list (<geom-bar>
                                       :bin-width (/ 1 20)
                                       :statistical-transformation i::+stat-identity+
                                       :position-adjustment (i::<position-dodge>)))
                        :scales (list (make-scale :discrete :x)
                                      (make-scale :continuous :y)
                                      (make-scale :discrete :ink)))
            plots))
    (reverse plots)))

(defun draw-benches ()
  (let ((plots (benches)))
    (com-draw-plots plots)))

(define-demo-plot *bench*
    (let ((dataset (read-data "~/Workshop/Repositories/cl-bench/output/")))
      (<polyclot> :title "Common Lisp Benchmark"
                  :width 1280 :height 500
                  :dataset dataset
                  :aesthetics (list :x "Test" :y "Time" :ink "Lisp")
                  ;:faceting (<faceting-wrap> :var '("Batch") :ncol 1)
                  :layers (list (<geom-bar>
                                 :bin-width (/ 1 20)
                                 :statistical-transformation i::+stat-identity+
                                 :position-adjustment (i::<position-dodge>)))
                  :scales (list (make-scale :discrete :x)
                                (make-scale :continuous :y)
                                (make-scale :discrete :ink))))
  "Common Lisp Benchmarks example plot")

;; (find-application-frame 'a-repl :width 800 :height 600)



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










>
>






|













<
<
|
<
|
<
>
|
<
|
<
<



|








|
|





|




|



|








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


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
(in-package "EU.TURTLEWARE.POLYCLOT-USER")


(define-application-frame a-repl ()
  ()
  (:panes (int :interactor :text-style (make-text-style :fix nil nil)
                           :end-of-line-action :allow
                           :scroll-bars t)
          (dodge (make-pane 'clime:box-adjuster-gadget))
          (app :application :text-style (make-text-style :fix nil :small)
                            :end-of-line-action :allow
                            :scroll-bars t)))

(define-a-repl-command (com-quit :name "quit") ()
  (with-application-frame (frame)
    (frame-exit frame)))

(define-a-repl-command (com-clear :name "clear") ()
  (with-application-frame (frame)
    (window-clear (frame-standard-output frame))
    (window-clear (frame-query-io frame))))

(define-a-repl-command (com-draw-plot :name "draw plot")
    ((plot '<polyclot> :gesture (:select :echo t)))
  (let ((stream *standard-output*))
    (window-clear stream)
    (with-room-for-graphics (stream :first-quadrant nil)
      (polyclot plot stream))
    (finish-output stream)))

(define-a-repl-command (com-draw-plots :name "draw plots")
    ((plots 't))
  (let ((plots (if (listp plots) plots (list plots)))
        (stream *standard-output*))
    (window-clear stream)
    (loop for plot in plots do
      (with-room-for-graphics (stream :first-quadrant nil)
        (polyclot plot stream))
      (terpri stream))
    (finish-output stream)))

(defmethod run-frame-top-level ((frame a-repl) &rest args)
  (declare (ignore args))
  (let ((*standard-input* (frame-standard-input frame))
        (*standard-output* (frame-standard-output frame))
        (*error-output* (frame-error-output frame))
        (*query-io* (frame-query-io frame))
        (*command-dispatchers* '(#\,)))
    (unwind-protect (repl)
      (frame-exit frame))))

(defun rep ()
  (fresh-line *query-io*)
  (multiple-value-bind (command-or-form ptype)
      (accept 'command-or-form :prompt (format nil "~a: " (package-name *package*))
                               :prompt-mode :raw
                               :default (values)
                               :stream *query-io*)
    (when (presentation-subtypep ptype 'command)
      (with-application-frame (frame)
        (return-from rep (execute-frame-command frame command-or-form))))
    (shiftf +++ ++ + - command-or-form)
    (with-room-for-graphics (*query-io* :first-quadrant nil)
      (shiftf /// // / (multiple-value-list (eval -))))
    (shiftf *** ** * (first /))
    (format *query-io* "~& ")
    (formatting-table (*query-io*)
      (loop for val in /
            for ptp = (presentation-type-of val)
            do (with-output-as-presentation (*query-io* val ptp :single-box t)
                 (formatting-row (*query-io*)
                   (formatting-cell (*query-io* :min-width 50)
                     (with-drawing-options (*query-io* :ink +blue+)
                       (format *query-io* "~s" val)))
                   (formatting-cell (*query-io* :min-width 50)
                     (with-drawing-options (*query-io* :text-face :italic :ink +dark-grey+)
                       (format *query-io* "~a" ptp)))))))))

(defun repl ()
  (let ((*package* (find-package "EU.TURTLEWARE.POLYCLOT-USER")))
   (loop (with-simple-restart (abort "Return to CLIM's top level.")
           (rep)))))

;;; Results of CL-bench are stored in files - one for each implementation -
;;; with a single form inside: (LISP-NAME . RESULTS) where RESULTS is a list
;;; of test cases in a form (TEST-NAME REAL-TIME USER-TIME SYS-TIME CONSED).
;;; If a statistic is not possible to for the implementation to produce, then
;;; it is NIL. For now we will focus on the user time.
;;;
;;; 1. NIL is "not available"
;;; 2. CL aesthetic is "ink"
;;; 3. CL bars are dodged on x axis

(defparameter *output-dir* "~/Workshop/Repositories/cl-bench/output/")

(defun read-data (output-dir)
  "Constructs a poor man's data frame."
  (flet ((process-result (form)
           (destructuring-bind (lisp . tests) form
             (loop for i from 0
                   for (test real user sys cons) in tests
                   for batch = (floor i 4)
                   when user            ; FIXME handle gracefully n/a
                     collect (list lisp test user batch)))))
    (cons (list "Lisp" "Test" "Time" "Batch")
          (loop with *read-eval* = nil
                for file in (directory (merge-pathnames "CL-benchmark*.*" output-dir))
                for form = (with-open-file (stream file :direction :input)
                             (read stream))
                append (process-result form)))))

(defun normalize-results (dataset)
  (let ((results (group-by '("Test") dataset))
        (newdata '()))
    (i::dohash ((test test-data) results)


      (declare (ignore test))

      (let ((data-body (rest test-data)))

        (loop with loser = (reduce #'max data-body :key #'third)
              for (lisp-name test-name time batch) in data-body

              do (push (list lisp-name test-name time batch) newdata))))


    (list* (car dataset) (reverse newdata))))

(defun yah ()
  (let ((dataset (read-data *output-dir*)))
    (normalize-results dataset)))

;;; time1 - 1
;;; time2 - ?

;;; FIXME come up with faceting so that test X is not shared among plots
;;; NCOL doesn't work etc
(defun benches ()
  (let* ((dataset-raw (read-data *output-dir*))
         (dataset (normalize-results dataset-raw))
         (groups (group-by '("Batch") dataset))
         (plots nil))
    (i::dohash ((batch dataset) groups)
      (declare (ignore batch))
      (push (<polyclot> :title "Common Lisp Benchmark"
                        :width 800 :height 280
                        :dataset dataset
                        :aesthetics (list :x "Test" :y "Time" :ink "Lisp")
                                        ;:faceting (<faceting-wrap> :var '("Batch") :ncol 1)
                        :layers (list (<geom-bar>
                                       :bin-width (/ 1 5)
                                       :statistical-transformation i::+stat-identity+
                                       :position-adjustment (i::<position-dodge>)))
                        :scales (list (make-scale :discrete :x)
                                      (make-scale :continuous :y :min-pos 0 :max-pos 4)
                                      (make-scale :discrete :ink)))
            plots))
    (reverse plots)))

(defun draw-benches ()
  (let ((plots (benches)))
    (com-draw-plots plots)))

















;; (find-application-frame 'a-repl :width 800 :height 600)