Commit b9aa4cdd authored by Yuanle Song's avatar Yuanle Song
Browse files

add haskell postgresql-simple benchmark

parent 5d67648d
Loading
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
* COMMENT -*- mode: org -*-
#+Date: 2016-12-16
Time-stamp: <2016-12-16>
Time-stamp: <2016-12-17>

* database binding benchmark
I want to know the efficiency of the db binding for different language,
@@ -39,3 +39,21 @@ https://www.postgresql.org/docs/9.4/static/libpq.html
26.2

//side note: why adding -shared in LDFLAGS will just segfault the program?
** postgres 9.4, lts-7.13, ghc 8.0.1, postgresql-simple
0.71
27.5
--
0.63
27.2
--
0.61
26.2
** postgres 9.4, lts-5.18, ghc 7.10.3, postgresql-simple
0.61
26.6
--
0.59
26.8
--
0.63
26.6
+32 −0
Original line number Diff line number Diff line
module Main where

import Control.Monad
import Text.Printf
import Data.Time.Clock
import Database.PostgreSQL.Simple

times :: Int
times = 3000

selectTest :: Connection -> IO ()
selectTest conn = do
  replicateM_ times (query_ conn "SELECT id, bar FROM foo" :: IO [(Int, Int)])

updateTest :: Connection -> IO ()
updateTest conn =
    replicateM_ times $ execute_ conn "UPDATE foo SET bar=bar+1 WHERE id=1"

timeit :: IO a -> IO a
timeit action = do
  start <- getCurrentTime
  r <- action
  end <- getCurrentTime
  printf "seconds: %f\n" (realToFrac $ diffUTCTime end start :: Double)
  return r

main :: IO ()
main = do
  conn <- connectPostgreSQL "host=localhost dbname=t1 user=t1 password=fNfwREMqO69TB9YqE+/OzF5/k+s="
  timeit $ selectTest conn
  timeit $ updateTest conn
  close conn
+30 −0
Original line number Diff line number Diff line
Copyright Yuanle Song (c) 2016

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * Neither the name of Yuanle Song nor the names of other
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
test postgres-simple db binding
+2 −0
Original line number Diff line number Diff line
import Distribution.Simple
main = defaultMain
Loading