-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lisp
261 lines (215 loc) · 8.42 KB
/
test.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
(in-package #:xdb2)
;;;;Test
(defparameter *tree* nil)
(defclass test-doc-non-storable ()
((id :initarg :id)
(eid :initarg :eid)
(aa :initarg :aa)
(bb :initarg :bb)
(cc :initarg :cc)
(dd :initarg :dd)
(ee :initarg :ee)
(ff :initarg :ff)
(hh :initarg :hh)
(data :initarg :data
:initform (make-hash-table)
:accessor data)
(key :initarg :key
:initform nil
:accessor key)
(type :initarg :type
:initform nil))
)
(defclass test-doc-storable ()
((id :initarg :id)
(eid :initarg :eid)
(aa :initarg :aa)
(bb :initarg :bb)
(cc :initarg :cc)
(dd :initarg :dd)
(ee :initarg :ee)
(ff :initarg :ff)
(hh :initarg :hh)
(data :initarg :data
:initform (make-hash-table)
:accessor data)
(key :initarg :key
:initform nil
:accessor key)
(type :initarg :type
:initform nil))
(:metaclass storable-class))
(defun make-doc-test (type key data)
(let ((doc-obj (make-instance 'test-doc-storable :key key :type type)))
(dolist (pair data)
(setf (gethash (first pair) (data doc-obj)) (second pair)))
doc-obj))
(defun test-store-doc (collection times)
(dotimes (i times)
(store-doc collection
(make-doc-test
"Test Doc"
i
(list
(list "id" i)
(list "eid" i)
(list "aa" (format nil "~R" (random 51234)))
(list "bb" (format nil "~R" (random 1234)))
(list "cc" (format nil "~R" (random 1234)))
(list "dd" (format nil "~R" (random 1234)))
(list "ee" (format nil "~R" (random 1234)))
(list "ff" (format nil "~R" (random 1234)))
(list "gg" (format nil "~R" (random 1234)))
(list "hh" (format nil "~R" (random 1234))))))))
(defun test (n)
(let* ((db (make-instance 'xdb :location "/tmp/db-test/"))
(col (add-collection db "test" :load-from-file-p nil)))
(time (test-store-doc col n))
;; (time (snapshot db))
;; (time (sum col "eid"))
;; (time (find-doc col "eid" 50))
;; (time (sort-collection col))
))
(defun test-store-docx (collection times)
(dotimes (i times)
(store-doc collection
(make-doc-test
"Test Doc"
i
(list
(list "id" i)
(list "eid" i)
(list "aa" (random 51234))
(list "bb" (format nil "~R" (random 1234)))
(list "cc" (format nil "~R" (random 1234)))
(list "dd" (format nil "~R" (random 1234)))
(list "ee" (format nil "~R" (random 1234)))
(list "ff" (format nil "~R" (random 1234)))
(list "gg" (format nil "~R" (random 1234)))
(list "hh" (get-universal-time))))
)
(if (equal (mod i 100000) 0)
(sb-ext:gc :full t))))
(defun test-store-doc-storable-object (collection times)
(dotimes (i times)
(store-doc collection
(make-instance 'test-doc-storable :key i :type "Test Doc"
:id i
:eid i
:aa (random 51234)
:bb (format nil "~R" (random 1234))
:cc (format nil "~R" (random 1234))
:dd (format nil "~R" (random 1234))
:ee (format nil "~R" (random 1234))
:ff (format nil "~R" (random 1234))
:hh (get-universal-time))
)
(if (equal (mod i 100000) 0)
(sb-ext:gc :full t))))
(defun test-store-doc-non-storable-object (collection times)
(dotimes (i times)
(store-doc collection
(make-instance 'test-doc-non-storable :key i :type "Test Doc"
:id i
:eid i
:aa (random 51234)
:bb (format nil "~R" (random 1234))
:cc (format nil "~R" (random 1234))
:dd (format nil "~R" (random 1234))
:ee (format nil "~R" (random 1234))
:ff (format nil "~R" (random 1234))
:hh (get-universal-time))
)
(if (equal (mod i 100000) 0)
(sb-ext:gc :full t))))
(defun test-store-doc-hash (collection times)
(dotimes (i times)
(let ((hash (make-hash-table :test 'equal)))
(setf (gethash 'key hash) i)
(setf (gethash "id" hash) i)
(setf (gethash "eid" hash) i)
(setf (gethash "bb" hash) (format nil "~R" (random 1234)))
(setf (gethash "cc" hash) (format nil "~R" (random 1234)))
(setf (gethash "dd" hash) (format nil "~R" (random 1234)))
(setf (gethash "ee" hash) (format nil "~R" (random 1234)))
(setf (gethash "ff" hash) (format nil "~R" (random 1234)))
(setf (gethash "stamp" hash) (get-universal-time))
(store-doc collection hash))
(if (equal (mod i 100000) 0)
(sb-ext:gc :full t))))
(defun test-store-doc-list (collection times)
(dotimes (i times)
(store-doc collection (list
(list 'key i)
(list "id" i)
(list "eid" i)
(list "aa" (random 51234))
(list "bb" (format nil "~R" (random 1234)))
(list "cc" (format nil "~R" (random 1234)))
(list "dd" (format nil "~R" (random 1234)))
(list "ee" (format nil "~R" (random 1234)))
(list "ff" (format nil "~R" (random 1234)))
(list "gg" (format nil "~R" (random 1234)))
(list "stamp" (get-universal-time))))
(if (equal (mod i 100000) 0)
(sb-ext:gc :full t))))
#|
(defparameter db (make-instance 'xdb :location "/tmp/db-test/"))
(defparameter col-hash (add-collection db "test-hash" :load-from-file-p nil))
(format t "Hash Test~%")
(format t "Store~%")
(time (test-store-doc-hash col-hash 10000))
(format t "Sum~%")
(time (sum col-hash :element "id"))
(format t "Find~%")
(time (find-doc col-hash :test (lambda (doc) (equal (get-val doc "id") 500))))
(format t "Sort~%")
(time (sort-collection col-hash))
(defparameter col-list (add-collection db "test-list" :load-from-file-p nil))
(format t "List Test~%")
(format t "Store~%")
(time (test-store-doc-list col-list 10000))
(format t "Sum~%")
(time (sum col-list :element "id"))
(format t "Find~%")
(time (find-doc col-list :test (lambda (doc) (equal (get-val doc "id") 500))))
(format t "Sort~%")
(time (sort-collection col-list))
(defparameter col-object (add-collection db "test-object" :load-from-file-p nil))
(format t "Object non storable Test~%")
(format t "Store~%")
(time (test-store-doc-non-storable-object col-object 10000))
(format t "Sum~%")
(time (sum col-object :element 'id))
(format t "Find~%")
(time (find-doc col-object :test (lambda (doc) (equal (get-val doc 'id) 500))))
(format t "Sort~%")
(time (sort-collection col-object))
(defparameter col-object-storable (add-collection db "test-object-storable" :load-from-file-p nil))
(setf *fsync-data* nil)
(format t "Object storable Test~%")
(format t "Store~%")
(time (test-store-doc-storable-object col-object-storable 10000))
(format t "Sum~%")
(time (sum col-object-storable :element 'id))
(format t "Find~%")
(time (find-doc col-object-storable :test (lambda (doc) (equal (get-val doc 'id) 500))))
(format t "Sort~%")
(time (sort-collection col-object-storable))
(time (let ((x (sort-collection-temporary col)))
(declare (ignore x))
"done"))
|#
(defparameter *test-db* (list 1 2 3 4))
(defmacro with-db (spec &body body)
"Locally establish a database connection, and bind *database* to it."
`(let ((*test-db* ,spec))
(unwind-protect (progn ,@body)
)))
(defclass xxx ()
())
(defgeneric test-withxx (db &key test-db))
(defmethod test-withxx ((collection xxx) &key (test-db *test-db*))
(princ test-db))
(with-db (list 9 9 9)
(test-withxx (make-instance 'xxx)) )