-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathMain.hs
More file actions
76 lines (64 loc) · 2.66 KB
/
Main.hs
File metadata and controls
76 lines (64 loc) · 2.66 KB
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
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}
module Main where
import Criterion.Main
import Control.Exception (SomeException)
import Control.Monad (void, replicateM, liftM, when, forM_)
import Control.Monad.Trans.Reader
import Data.Aeson (Value(..))
import Database.Persist.TH (mkPersist, mkMigrate, share, sqlSettings, persistLowerCase, persistUpperCase, MkPersistSettings(..))
import Database.Persist.Sql.Raw.QQ
import Database.Persist.Postgresql.JSON()
import Data.Time.Clock (getCurrentTime)
import Control.Monad.IO.Class
import Control.Monad.IO.Unlift (MonadUnliftIO)
import UTCTimeSetup
import Control.Monad.Logger
import Database.Persist.Sql
import Database.Persist.Postgresql
import System.Log.FastLogger (fromLogStr)
import Chronos (now, Offset(..), timeToOffsetDatetime)
runConn :: MonadUnliftIO m => SqlPersistT (LoggingT m) t -> m ()
runConn f = runConn_ f >>= const (return ())
runConn_ :: MonadUnliftIO m => SqlPersistT (LoggingT m) t -> m t
runConn_ f = do
let debugPrint = False
let printDebug = if debugPrint then print . fromLogStr else void . return
flip runLoggingT (\_ _ _ s -> printDebug s) $ do
withPostgresqlPool ("host=" <> "localhost" <> " port=5432 user=postgres dbname=test") 1 $ runSqlPool f
setup :: MonadIO m => Migration -> ReaderT SqlBackend m ()
setup migration = do
printMigration migration
runMigrationUnsafe migration
-- Our benchmark harness.
main = do
runConn $ do
mapM_ setup
[ utcTimeBenchmarkMigration
]
runConn $ do
deleteWhere ([] :: [Filter UserWithTimestamps])
-- currTime <- getCurrentTime
currTime <- now
let utcNow = timeToOffsetDatetime (Offset 0) currTime
let manyUsers = replicate 10000 $ UserWithTimestamps "first" "last" utcNow utcNow
runConn $ do
insertMany_ manyUsers
let debugPrint = False
let printDebug = if debugPrint then print . fromLogStr else void . return
-- flip runLoggingT (\_ _ _ s -> printDebug s) $ do
runNoLoggingT $ do
withPostgresqlPool ("host=" <> "localhost" <> " port=5432 user=postgres dbname=test") 1 $ \pool -> do
NoLoggingT (defaultMain
[ bench "postAdminOrganizationsStatusR" $ whnfIO (runSqlPool (selectList ([] :: [Filter UserWithTimestamps]) []) pool)
])