hasql/benchmark/Main.hs
2015-11-22 10:10:21 +03:00

53 lines
1.4 KiB
Haskell

module Main where
import Main.Prelude
import Criterion.Main
import qualified Hasql.Connection as HC
import qualified Hasql.Settings as HS
import qualified Hasql.Query as HQ
import qualified Hasql.Encoding as HE
import qualified Hasql.Decoding as HD
import qualified Main.Queries as Q
main =
HC.connect settings >>= either (fail . show) use
where
settings =
HS.settings host port user password database
where
host = "localhost"
port = 5432
user = "postgres"
password = ""
database = "postgres"
use connection =
defaultMain
[
bgroup "decoding"
[
bgroup "1 column"
[
bench "1 row" $ nfIO $! query () $! Q.select1 1
,
bench "100 rows" $ nfIO $! query () $! Q.select1 100
,
bench "10000 rows" $ nfIO $! query () $! Q.select1 10000
]
,
bgroup "4 columns"
[
bench "1 row" $ nfIO $! query () $! Q.select4 1
,
bench "100 rows" $ nfIO $! query () $! Q.select4 100
,
bench "10000 rows" $ nfIO $! query () $! Q.select4 10000
]
]
]
where
query :: a -> HQ.Query a b -> IO b
query params query =
{-# SCC "query" #-}
HQ.run query params connection >>= either (fail . show) pure