Skip to content

Instantly share code, notes, and snippets.

@smanek
Created December 31, 2009 13:02
Show Gist options
  • Save smanek/266719 to your computer and use it in GitHub Desktop.
Save smanek/266719 to your computer and use it in GitHub Desktop.
(defvar *bdb-connection* (elephant:open-store (list :BDB "/home/smanek/lisp-db-bench/bdb")))
(defun get-next-guid ()
(let ((n (1+ (or (ele:get-from-root "*next-guid*")
0))))
(ele:add-to-root "*next-guid*" n)))
(ele:defpclass ele-class ()
((score :accessor get-score
:initarg :score
:initform 0
:index t)
(category :accessor get-category
:initarg :category
:initform :default
:index t)
(time :accessor get-time
:initarg :time
:initform (get-universal-time)
:index t)
(guid :reader get-guid
:initform (get-next-guid)
:index t)))
(defun test-1-ele ()
(ele:with-transaction ()
(dotimes (i 100000)
(make-instance 'ele-class :category (nth (random 3) (list :A :B :C))
:time (+ (get-universal-time) (random 10000000))))))
(defun test-2-ele ()
(ele:map-class #'(lambda (inst)
(ele:with-transaction ()
(dotimes (i 20)
(if (plusp (random 2))
(incf (get-score inst))
(decf (get-score inst))))))
'ele-class))
(defun test-3-ele ()
(flet ((get-instances-by-slot (class slot count)
(ele:with-transaction ()
(mapcar #'(lambda (oid)
(ele::controller-recreate-instance ele:*store-controller* oid))
(ele:with-btree-cursor (curs (ele:find-inverted-index class slot))
(loop with i = 0
for (m k v) = (multiple-value-list (ele:cursor-last curs))
then (multiple-value-list (ele:cursor-prev curs))
while (and m (if count
(<= (incf i) count)
t))
collect v))))))
(mapcar #'(lambda (count)
(ele:with-transaction ()
(mapcar #'get-guid
(get-instances-by-slot 'ele-class 'score count))))
(list 10 100 1000))))
(defun test-4-ele ()
(flet ((get-top-in-category (category count)
(ele:with-transaction ()
(ele:with-btree-cursor (curs (ele:find-inverted-index 'ele-class 'score))
(loop with res = nil
for (m k v) = (multiple-value-list (ele:cursor-last curs))
then (multiple-value-list (ele:cursor-prev curs))
while (< (length res) count)
do (let ((inst (ele::controller-recreate-instance ele:*store-controller* v)))
(when (eq (get-category inst) category)
(setf res (cons inst res))))
finally (return (mapcar #'get-guid res)))))))
(list
(get-top-in-category :a 10)
(get-top-in-category :a 100)
(get-top-in-category :a 1000))))
(defun test-5-ele ()
(ele:with-transaction ()
(ele:map-class #'(lambda (instance)
(ele:drop-instance instance))
'ele-class)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment