Commit 454c275f authored by Yuanle Song's avatar Yuanle Song
Browse files

add sbcl postmodern result

parent 6c8684dc
Loading
Loading
Loading
Loading
+32 −11
Original line number Diff line number Diff line
* COMMENT -*- mode: org -*-
#+Date: 2016-12-16
Time-stamp: <2017-01-25>
Time-stamp: <2017-01-26>

* database binding benchmark
I want to know the efficiency of the db binding for different language,
@@ -20,19 +20,20 @@ libraries and database servers.
each entry has format: db_server, compiler, libraries
all build is release mode (with -O or equivalent).

| db    | language/runtime  | lib               | select (s) | update (s) |
|-------+-------------------+-------------------+------------+------------|
| pg9.4 | python/cpython2.7 | psycopg2          |       0.37 |       26.3 |
| pg9.4 | C/gcc             | libpq5            |       0.32 |       26.5 |
| pg9.4 | haskell/ghc8.0.1  | postgresql-simple |       0.63 |       27.2 |
| pg9.4 | haskell/ghc7.10.3 | postgresql-simple |       0.61 |       26.6 |
| pg9.4 | rust/rust1.13.0   | postgres          |       0.50 |       26.3 |
| pg9.4 | go/go1.7.3        | pq                |       0.37 |       27.2 |
| pg9.4 | racket/racket6.5  | built-in db       |       1.99 |       26.7 |
| db    | language    | runtime       | lib               | select (s) | update (s) |
|-------+-------------+---------------+-------------------+------------+------------|
| pg9.4 | python      | cpython 2.7.9 | psycopg2          |       0.37 |       26.3 |
| pg9.4 | C           | gcc 4.9.2     | libpq5            |       0.32 |       26.5 |
| pg9.4 | haskell     | ghc 8.0.1     | postgresql-simple |       0.63 |       27.2 |
| pg9.4 | haskell     | ghc 7.10.3    | postgresql-simple |       0.61 |       26.6 |
| pg9.4 | rust        | rust 1.13.0   | postgres          |       0.50 |       26.3 |
| pg9.4 | go          | go 1.7.3      | pq                |       0.37 |       27.2 |
| pg9.4 | racket      | racket 6.5    | built-in db       |       1.99 |       26.7 |
| pg9.4 | common lisp | sbcl 1.2.11   | postmodern        |       0.57 |       27.0 |

- Remarks:
  - python and go's db binding is as fast as C.
  - rust and haskell is slower. C is 1.65x faster.
  - rust, haskell, cl is slower. C is 1.5x faster.
  - racket is much slower. C is 5x faster.

** postgres 9.4, cpython 2.7, psycopg2==2.6.1
@@ -142,3 +143,23 @@ https://www.postgresql.org/docs/9.4/static/libpq.html
  26.79

  it's still the slowest.
** postgres 9.4, sbcl 1.2.11, postmodern 20160208
0.54
26.69
--
0.57
27.02
--
0.58
27.16

- try enable optimize
  C-c C-k with negative prefix

  time arithmetic doesn't matter.
  0.58
  27.28
  --
  0.54
  28.51
  no effect.
+36 −0
Original line number Diff line number Diff line
;; (quicklisp:quickload "postmodern")

(defpackage :db-bench
  (:use :common-lisp :postmodern))

(in-package :db-bench)

(defconstant +TIMES+ 3000)

;; (query "SELECT id, bar FROM foo")
;; (query (:select 'id 'bar :from 'foo))

;; (execute "UPDATE foo SET bar=bar+1 WHERE id=1")
;; (execute (:update 'foo :set 'bar (:+ 'bar 1) :where (:= 'id 1)))

(defmacro timeit (stmt times)
  (let ((start-sec (gensym))
	(start-msec (gensym)))
    `(multiple-value-bind (,start-sec ,start-msec) (sb-ext:get-time-of-day)
       (dotimes (_ ,times)
	 ,stmt)
       (format t "~,2f~%" (multiple-value-bind (end-sec end-msec) (sb-ext:get-time-of-day)
			    (/ (- (+ (* end-sec 1000000) end-msec)
				  (+ (* ,start-sec 1000000) ,start-msec))
			       1000000))))))

(defun select-test ()
  (timeit (query (:select 'id 'bar :from 'foo)) +TIMES+))
(defun update-test ()
  (timeit (execute (:update 'foo :set 'bar (:+ 'bar 1) :where (:= 'id 1))) +TIMES+))

(defun main ()
  (connect-toplevel "t1" "t1" "fNfwREMqO69TB9YqE+/OzF5/k+s=" "localhost")
  (select-test)
  (update-test)
  (disconnect-toplevel))
+9 −0
Original line number Diff line number Diff line
(in-package :asdf)

(defsystem "db-binding-benchmark"
  :description "db binding benchmark"
  :version "0.1.0"
  :author "Yuanle Song <sylecn@gmail.com>"
  :licence "GPLv3"
  :components ((:file "bench"))
  :depends-on (:postmodern))