chronograph 0.1.0.0 → 0.2.0.0
raw patch · 2 files changed
+37/−16 lines, 2 filesdep +thymedep +vector-spacedep −time
Dependencies added: thyme, vector-space
Dependencies removed: time
Files
- chronograph.cabal +3/−2
- src/Data/Chronograph.hs +34/−14
chronograph.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: chronograph-version: 0.1.0.0+version: 0.2.0.0 synopsis: measure timings of data evaluation description: The 'Chronograph' data structure adds a measure field to an existing Haskell expression. This field will be the@@ -34,7 +34,8 @@ build-depends: base >=4.5 && < 5.0, ghc-prim >=0.2 && < 0.4, deepseq ==1.3.*,- time ==1.4.*+ thyme >= 0.3 && < 0.4,+ vector-space >= 0.6 && < 0.9 hs-source-dirs: src source-repository head
src/Data/Chronograph.hs view
@@ -14,16 +14,11 @@ -- > import Control.Applicative -- > import Data.Chronograph -- >- -- > import Text.Printf- -- >- -- > formatOutput :: FilePath -> Chronograph Int -> String- -- > formatOutput fp chr = printf "%s :: %d, %s" fp (val chr) (show $ measure chr)- -- >- -- > procFile :: FilePath -> IO ()+ -- > procFile :: FilePath -> IO Int -- > procFile fp = do -- > doc <- readFile fp -- > let wc = length $ lines doc- -- > putStrLn $ formatOutput fp (chrono wc)+ -- > chronoPrint "time to eval length" (chrono wc) -- -- 'chrono' creates a chronograph that evaluates its input as far as 'seq' would. -- In this case the input 'wc' is an Int, so 'chrono' fully evaluates it.@@ -41,7 +36,7 @@ -- > procIO :: FilePath -> IO () -- > procIO fp = do -- > wc <- chronoIO $ fileLinesIO fp- -- > putStrLn $ formatOutput fp wc+ -- > void $ chronoPrint "fileLinesIO" wc -- -- > main :: IO () -- > main = do@@ -62,16 +57,24 @@ , chronoIO , chronoNFIO , chronoIOBy+-- * utility functions+, chronoPrint+, chronoTraceEvent+, chronoTraceEventIO ) where +import Control.Applicative import Control.DeepSeq-import Data.Time (NominalDiffTime, getCurrentTime, diffUTCTime)+import Data.Thyme (NominalDiffTime, getCurrentTime)+import Data.Thyme.Format.Human+import Data.AffineSpace ((.-.))+import Debug.Trace import GHC.Generics import System.IO.Unsafe (unsafePerformIO) data Chronograph a = Chronograph- { val :: a- , measure :: NominalDiffTime+ { measure :: {-# UNPACK #-} !NominalDiffTime+ , val :: a } deriving (Show, Generic) ----------------------------------------------------------@@ -91,7 +94,7 @@ let measure = unsafePerformIO $ do t0 <- getCurrentTime t1 <- eval x `seq` getCurrentTime- return (t1 `diffUTCTime` t0)+ return (t1 .-. t0) in Chronograph {val = measure `seq` x, measure } ----------------------------------------------------------@@ -118,6 +121,23 @@ t0 <- getCurrentTime val <- mx t1 <- eval val `seq` getCurrentTime- let measure = t1 `diffUTCTime` t0-+ let measure = t1 .-. t0 return $ Chronograph {val, measure}++----------------------------------------------------------+-- utility functions++-- | print the measure to stdout and return the value+chronoPrint :: String -> Chronograph a -> IO a+chronoPrint x cr =+ val cr <$ putStrLn (x ++ ": " ++ humanTimeDiff (measure cr))++-- | write the measure to the ghc eventlog and return the value+chronoTraceEvent :: String -> Chronograph a -> a+chronoTraceEvent x cr =+ traceEvent (x ++ ": " ++ humanTimeDiff (measure cr)) $ val cr++-- | write the measure to the ghc eventlog and return the value in IO+chronoTraceEventIO :: String -> Chronograph a -> IO a+chronoTraceEventIO x cr =+ val cr <$ traceEventIO (x ++ ": " ++ humanTimeDiff (measure cr))