-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.hs
43 lines (38 loc) · 1.5 KB
/
Main.hs
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
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Criterion.Measurement
import Criterion.Measurement.Types (Measured (..), nfAppIO)
import qualified Data.Text.Lazy as T
import Data.Time (getCurrentTime)
import MyLib
import Numeric
import System.Directory (getCurrentDirectory)
import System.Environment
import System.Process
-- | A sandwich takes five minutes according to my poll: https://twitter.com/shapr/status/1263950892744806402
sandwichSeconds :: Double
sandwichSeconds = 5 * 60
-- | How many words at the beginning of the command line to match?
wordsToMatch :: Int
wordsToMatch = 5
main :: IO ()
main = do
history <- readSandWatchData
args <- getArgs
now <- getCurrentTime
thiscwd <- getCurrentDirectory
let thisRun = Run now (T.strip . T.pack $ unwords args) (T.pack thiscwd) 0 0 0 -- could I treat cmdline params as a Set?
let guess = guessTime wordsToMatch history thisRun
putStrLn $ "This command will probably take " <> formatFloat (guess / (5 * 60)) <> " sandwiches to complete."
let bmark = nfAppIO callCommand (unwords args)
(msr, _) <- measure bmark 1
let thisRun' =
thisRun
{ runTime = measTime msr,
cpuTime = measCpuTime msr,
cpuCycles = measCycles msr
}
writeSandWatchData $ Runs (thisRun' : rs history)
putStrLn $ "Estimated time was " <> formatFloat (guess / (5 * 60)) <> " sandwiches, actual time was " <> formatFloat (measTime msr / sandwichSeconds) <> " sandwiches."
where
formatFloat f = showFFloat (Just 2) f ""