-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmarks.lisp
357 lines (313 loc) · 12.1 KB
/
benchmarks.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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
;;(quicklisp:quickload "cl-store")
;;#-(or lispworks allegro)(quicklisp:quickload "hyperluminal-mem")
;;(quicklisp:quickload "cl-conspack")
;;#+sbcl (require 'sb-sprof)
(in-package :cl-binary-store)
(defmacro timed ((annotation &optional (repeats 1) output-size-MB) &body body)
(let ((start (gensym))
(end (gensym)))
`(let ((,start (get-internal-real-time)))
(multiple-value-prog1
,@body
(let* ((,end (get-internal-real-time)))
(cond
((= ,end ,start)
(format t "~A too fast to resolve~%" ,annotation))
(t
(let ((ms-per (/ (- ,end ,start)
(* 0.001f0 internal-time-units-per-second)
,repeats)))
(format t "~A ~,2f ms ~A~%" ,annotation ms-per
,(if output-size-MB
`(format nil "at ~d MB/sec" (round (/ ,output-size-MB ms-per 1f-3)))
""))))))))))
#-(or allegro abcl lispworks) ;; crashes on abcl
(defun test-hlmem-on-data (data &key (repeats 20))
(let* ((words (hyperluminal-mem:msize 0 data))
(output-size (/ (* 8 words) 1e6)))
(format t "HYPERLUMINAL-MEM~%")
(format t " OUTPUT SIZE: ~,2f MB~%" output-size)
(static-vectors:with-static-vector (a-store (* 8 words))
(timed (" WRITE:" repeats output-size)
(dotimes (x repeats)
(hyperluminal-mem::mwrite (static-vectors:static-vector-pointer a-store) 0 words data)))
;; returns words
(timed (" READ :" repeats output-size)
(dotimes (x repeats)
(hyperluminal-mem:mread (static-vectors:static-vector-pointer a-store) 0 words))))))
(defun test-cl-binary-store-on-data
(data &key (track-references t) (support-shared-list-structures nil) (repeats 20)
(read t) (write t) (file nil))
(let* ((cl-binary-store:*support-shared-list-structures* support-shared-list-structures)
(cl-binary-store:*track-references* track-references)
(store (coerce
(cl-binary-store:store nil data)
'(simple-array (unsigned-byte 8) (*))))
(size (length store))
(output-size-MB (/ size 1e6)))
(format t "CL-BINARY-STORE~%")
(format t " OUTPUT SIZE: ~,2f MB~%" output-size-MB)
(when write
(timed (" WRITE:" repeats output-size-MB)
(dotimes (x repeats) (cl-binary-store:store store data)))
(when file
(timed (" FILE WRITE:" repeats output-size-MB)
(dotimes (x repeats)
(with-open-file (str "blarg.bin" :if-exists :supersede :if-does-not-exist :create
:direction :output :element-type '(unsigned-byte 8))
(cl-binary-store:store str data))))))
(when read
(timed (" READ :" repeats output-size-MB)
(dotimes (x repeats) (cl-binary-store:restore store)))
(when file
(timed (" FILE READ :" repeats output-size-MB)
(dotimes (x repeats)
(with-open-file (str "blarg.bin" :direction :input :element-type '(unsigned-byte 8))
(cl-binary-store:restore str))))))
(values)))
(defun test-conspack-on-data (data &key (repeats 10) (read t) (write t) (to-file nil)
(track-references t))
(format t "CL-CONSPACK~%")
(let* ((encoded-data (if track-references
(conspack:tracking-refs ()
(conspack:encode data))
(conspack:encode data)))
(output-size-MB (/ (length encoded-data) 1e6)))
(format t " OUTPUT SIZE: ~,2fMB~%" output-size-MB)
(when write
(when to-file
(timed (" FILE WRITE:" repeats output-size-MB)
(dotimes (x repeats)
(with-open-file (str "blarg.bin" :if-exists :supersede :if-does-not-exist :create
:direction :output :element-type '(unsigned-byte 8))
(if track-references
(conspack:tracking-refs ()
(conspack:encode data :stream str))
(conspack:encode data :stream str))))))
(timed (" WRITE:" repeats output-size-MB)
(dotimes (x repeats)
(if track-references
(conspack:tracking-refs ()
(conspack:encode data))
(conspack:encode data)))))
(when read
(when to-file
(timed (" FILE READ :" repeats output-size-MB)
(dotimes (x repeats)
(with-open-file (str "blarg.bin" :element-type '(unsigned-byte 8))
(if track-references
(conspack:tracking-refs ()
(conspack:decode-stream str))
(conspack:decode-stream str))))))
(timed (" READ :" repeats output-size-MB)
(if track-references
(dotimes (x repeats)
(conspack:tracking-refs ()
(conspack:decode encoded-data)))
(dotimes (x repeats)
(conspack:decode encoded-data)))))
(values)))
(defun test-cl-store-on-data
(data &key (check-for-circs nil) (repeats 10) (read t) (write t)
(precise-list-storage nil))
;; if you try and dump it to a flexi-streams sequence it's 4x slower than this!
(let ((cl-store:*check-for-circs* check-for-circs)
(cl-store:*precise-list-storage* precise-list-storage))
(format t "CL-STORE~%")
(cl-store:store data "blarg.bin")
(let ((output-size-MB
(with-open-file (str "blarg.bin")
(/ (file-length str) 1e6))))
(format t " OUTPUT SIZE: ~,2fMB~%" output-size-MB)
(when write
(timed (" WRITE:" repeats output-size-MB)
(dotimes (x repeats) (cl-store:store data "blarg.bin"))))
(when read
(timed (" READ :" repeats output-size-MB)
(dotimes (x repeats) (cl-store:restore "blarg.bin")))))))
(defun test-on-data (data &key (hlmem t) (cl-store t) (cl-binary-store t) (conspack t))
#-(or allegro abcl lispworks)
(when hlmem
(test-hlmem-on-data data))
(when cl-binary-store
(test-cl-binary-store-on-data data :track-references (not hlmem)
:support-shared-list-structures (and (not hlmem)
(not cl-store))))
(when conspack
(test-conspack-on-data data :track-references (not hlmem)))
(when cl-store
(test-cl-store-on-data data :check-for-circs (not hlmem))))
;; Data to test on
(defun long-list-of-tiny-integers (&optional (n 1000000))
(loop repeat n collect (- (random 33) 16)))
(defun long-simple-vector-of-tiny-integers (&optional (n 1000000))
(coerce (long-list-of-tiny-integers n) 'simple-vector))
(defun long-list-of-not-tiny-integers (&optional (n 1000000))
(make-list n :initial-element (random 256)))
(defun long-list-of-random-fixnums (&optional (n 1000000))
(loop repeat n collect (random #-ccl(- (expt 2 61) (expt 2 60))
#+ccl (- (expt 2 59) (expt 2 58)))))
(defun long-list-of-random-double-floats (&optional (n 1000000))
(loop repeat n collect (random 1d0)))
(defun long-list-of-random-single-floats (&optional (n 1000000))
(loop repeat n collect (random 1f0)))
(defun long-list-of-random-complex-double-floats (&optional (n 1000000))
(loop repeat n collect (complex (random 1d0) (random 1d0))))
(defun long-list-of-big-ub8-vectors (&optional (n 1000))
(loop repeat n
collect
(coerce
(loop for i fixnum from 0 below 10000
collect 123)
'(simple-array (unsigned-byte 8) (*)))))
(defun long-list-of-big-simple-bit-vectors ()
(loop repeat 1000
collect
(coerce
(loop for i fixnum from 0 below 10000
collect (random 1))
'(simple-array bit (*)))))
(defun long-list-of-big-simple-double-float-vectors ()
(loop repeat 1000
collect
(coerce
(loop for i fixnum from 0 below 1000
collect (random 1d0))
'(simple-array double-float (*)))))
(defun list-of-double-float-matrices ()
(loop repeat 100
collect
(let ((m (make-array '(100 100) :element-type 'double-float)))
(dotimes (i 100)
(dotimes (j 100)
(setf (aref m i j) (random 1d0))))
m)))
(defun long-complex-list ()
(loop repeat 1000000 collect (if (> (random 1000) 500)
3.1415d0
;; (complex 1d0) ;; cl-store chokes
;; (random 1d0) ;; cl-store chokes
(if (> (random 100) 50)
;;(random 1f0) ;; <- makes cl-store take forever!
"hi" ;;(format nil "~A" (random 123))
(if (> (random 100) 50)
(cons (random 30) 2)
(if (= (random 2) 1)
(complex 1d0 1d0)
;; (random 1f0) slows cl-store crazily
#()))))))
(defun lots-of-the-same-string ()
(let ((string (coerce "asdf" 'simple-base-string)))
(loop for i fixnum from 0 below 1000000
collect string)))
(defun lots-of-keywords (&optional (n 100000))
"With some repeats"
(loop for i fixnum from 0 below n
collect (intern (format nil "~A" (random n)) 'keyword)))
(defun lots-of-symbols (&optional (N 100000))
"With some repeats"
(loop for i fixnum from 0 below n
collect (intern (format nil "~A" (random n)) 'cl-user)))
(defun lots-of-uninterned-symbols (&optional (N 100000))
"With some repeats"
(let ((symbol-pool (loop for i fixnum below (floor N 5) collect (gensym "HELLO"))))
(loop repeat 5 appending symbol-pool)))
(defstruct bench-blarg
a
b)
(conspack:defencoding bench-blarg
a b)
#-allegro
(defmethod hyperluminal-mem:msize-object ((b bench-blarg) index)
(hyperluminal-mem:msize* index (bench-blarg-a b) (bench-blarg-b b)))
#-allegro
(defmethod hyperluminal-mem:mwrite-object ((b bench-blarg) ptr index end-index)
(hyperluminal-mem:mwrite* ptr index end-index (bench-blarg-a b) (bench-blarg-b b)))
#-allegro
(defmethod hyperluminal-mem:mread-object ((type (eql 'bench-blarg)) ptr index end-index &key)
(hyperluminal-mem:with-mread* (a b new-index) (ptr index end-index)
(values
(make-bench-blarg :a a :b b)
new-index)))
(defun lots-of-structure-objects (&optional (n 100000))
(coerce
(loop for i below n
collect (make-bench-blarg :a (random 1d0) :b (coerce (format nil "~A" (random 100)) 'simple-base-string)))
'simple-vector))
(defclass c-blarg
()
((a :initarg :a)
(b :initarg :b)))
(conspack:defencoding c-blarg
a b)
(defun lots-of-standard-objects (&optional (n 100000))
(coerce
(loop for i below n
collect (make-instance 'c-blarg :a (random 256) :b "hello"))
'simple-vector))
(defun simple-base-strings ()
(loop for i below 100000
collect (coerce (format nil "~A" (random 1000000)) 'simple-base-string)))
(defun simple-strings ()
(loop for i below 100000
collect (format nil "~A~A" (random 1000000)
#+(or abcl allegro) (code-char #x03b1)
#-(or abcl allegro) #\U+03b1)))
(defun a-pile-of-tangled-conses (&optional (number 1000))
(let ((a (make-array number)))
(loop for n below number do (setf (svref a n) (cons nil nil)))
(loop repeat (* 10 number)
do (setf (car (svref a (random number)))
(svref a (random number)))
(setf (cdr (svref a (random number)))
(svref a (random number))))
a))
(defun a-bunch-of-specialized-arrays (&optional (n 10000))
(loop for type in '((unsigned-byte 1)
(unsigned-byte 2)
(unsigned-byte 4)
(unsigned-byte 8)
(unsigned-byte 16)
(unsigned-byte 32)
fixnum
(unsigned-byte 64)
(signed-byte 8)
(signed-byte 16)
(signed-byte 32)
(signed-byte 64)
single-float
double-float)
for elt in (list 1 2 15 255 65535 (1- (expt 2 32)) (expt 2 50) (1- (expt 2 64))
-1 -128 -32768 -100000 1f0 -1d0)
collect
(make-array n :element-type type :initial-element elt)))
(defstruct address
(street "Ave Greene" :type simple-string)
(state "QC" :type simple-string)
(zip "H3Z1Z9" :type simple-base-string))
(defstruct person
(first "Andrew" :type simple-string)
(second "Berkley" :type simple-string)
(age 49 :type (unsigned-byte 8)) ;; take that future people living to 256 years old!
(addresses nil :type list)
(telephone "" :type simple-base-string)
(email "" :type simple-string))
(defun a-lot-of-people-and-addresses (&optional (n 10000))
(let* ((addresses (coerce
(loop repeat n
collect (make-address :street (format nil "~A" (random 1000000))
:state (format nil "~A" (random 100))
:zip (format nil "~A" (random 100000))))
'simple-vector))
(people-with-addresses
(coerce
(loop repeat n
collect (make-person
:first (format nil "~A" (random 10000000))
:second (format nil "~A" (random 10000000))
:age (random 100)
:addresses (list (svref addresses (random n)))
:telephone (format nil "~A" (random 1000000))
:email (format nil "~A" (random 100000000))))
'simple-vector)))
people-with-addresses))