Created
November 20, 2014 09:20
-
-
Save ethercrow/03df8a24aa554ff2a1b8 to your computer and use it in GitHub Desktop.
Profile something by its stdout line by line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
import Control.Monad.Loops | |
import Data.Time.Clock.POSIX | |
import System.IO | |
main :: IO () | |
main = do | |
stampedLines <- whileM (not <$> isEOF) $ do | |
l <- getLine | |
t <- getPOSIXTime | |
putStrLn l | |
return (t, l) | |
tEnd <- getPOSIXTime | |
let timedLines = zipWith (\(t0, s0) t1 -> (t1 - t0, s0)) | |
stampedLines | |
(tail (fmap fst stampedLines) ++ [tEnd]) | |
putStrLn "\n-----------------\n" | |
mapM_ (\(t, s) -> putStrLn (concat [show t, "\t", s])) | |
timedLines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment