Skip to content

Instantly share code, notes, and snippets.

@ethercrow
Created November 20, 2014 09:20
Show Gist options
  • Save ethercrow/03df8a24aa554ff2a1b8 to your computer and use it in GitHub Desktop.
Save ethercrow/03df8a24aa554ff2a1b8 to your computer and use it in GitHub Desktop.
Profile something by its stdout line by line.
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