summaryrefslogtreecommitdiffhomepage
path: root/bench/main.hs
blob: 10639ebd99ec1decb717dc94bbae3d5dd492a342 (plain)
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
module Main (main) where

import Data.IORef (newIORef)
import Data.Time
import Gauge
import Xmobar
import Xmobar.Plugins.Monitors.Cpu

main :: IO ()
main = do
  defaultMain =<< sequence [cpuBench, dateBench]

mkCpuArgs :: IO CpuArguments
mkCpuArgs = getArguments ["-L", "3", "-H", "50", "--normal", "green", "--high", "red", "-t", "Cpu: <total>%"]

cpuBench :: IO Benchmark
cpuBench = do
  cpuArgs <- mkCpuArgs
  return $ bgroup "Cpu Benchmarks"
    [ bench "CPU normal args" $ nfIO (runCpu cpuArgs)
    ]

dateBench :: IO Benchmark
dateBench = do
  let format = "D: %B %d %A W%V"
  zone <- getCurrentTimeZone
  zone' <- newIORef =<< getCurrentTimeZone
  return $ bgroup "Date Benchmarks"
    [ bench "Date" $ nfIO (date zone' format)
    , bench "DateZonedTime" $ nfIO (dateZonedTime format)
    , bench "DateWithTimeZone" $ nfIO (dateWithTimeZone zone format)
    ]

dateZonedTime :: String -> IO String
dateZonedTime format = fmap (formatTime defaultTimeLocale format) getZonedTime

dateWithTimeZone :: TimeZone -> String -> IO String
dateWithTimeZone zone format =
    fmap (formatTime defaultTimeLocale format . utcToZonedTime zone) getCurrentTime