48070341874384cc13c591de5311fdfe5b3f7d90
[packages/time.git] / benchmark / Main.hs
1 {-# LANGUAGE PackageImports #-}
2 module Main where
3
4 import Criterion.Main
5 import Data.Time
6 import Data.Time.Clock.POSIX
7 import Data.Time.Clock.System
8
9 import qualified "time" Data.Time as O
10 import qualified "time" Data.Time.Clock.POSIX as O
11
12 main :: IO ()
13 main = do
14 getCurrentTime >>= print
15 O.getCurrentTime >>= print
16 getPOSIXTime >>= print . posixSecondsToUTCTime
17 O.getPOSIXTime >>= print . O.posixSecondsToUTCTime
18 getZonedTime >>= print
19 O.getZonedTime >>= print
20
21 _tz <- getCurrentTimeZone
22 ct <- getCurrentTime
23 _otz <- O.getCurrentTimeZone
24 oct <- O.getCurrentTime
25
26 defaultMain [
27 bgroup "getCurrentTime" [
28 bench "old" $ nfIO O.getCurrentTime,
29 bench "new" $ nfIO getCurrentTime
30 ],
31 bgroup "getPOSIXTime" [
32 bench "old" $ nfIO O.getPOSIXTime,
33 bench "new" $ nfIO getPOSIXTime
34 ],
35 bgroup "getSystemTime" [
36 bench "new" $ nfIO getSystemTime
37 ],
38 bgroup "getTimeZone" [
39 bench "old" $ nfIO $ O.getTimeZone oct,
40 bench "new" $ nfIO $ getTimeZone ct
41 ],
42 bgroup "getCurrentTimeZone" [
43 bench "old" $ nfIO O.getCurrentTimeZone,
44 bench "new" $ nfIO getCurrentTimeZone
45 ],
46 bgroup "getZonedTime" [
47 bench "old" $ nfIO O.getZonedTime,
48 bench "new" $ nfIO getZonedTime
49 ],
50 bgroup "formatTime" [
51 bench "old" $ nf (O.formatTime O.defaultTimeLocale "%a, %_d %b %Y %H:%M:%S %Z") oct,
52 bench "new" $ nf (formatTime defaultTimeLocale "%a, %_d %b %Y %H:%M:%S %Z") ct
53 ]
54 ]