Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Last active March 13, 2024 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramirez7/a63610820d9636a11925b68b6991ec6b to your computer and use it in GitHub Desktop.
Save ramirez7/a63610820d9636a11925b68b6991ec6b to your computer and use it in GitHub Desktop.
Get the _real_ time of stuff in ghci
:{
let ghciTime cmd = do
let mkVar n u = "ghciTime_" ++ n ++ "_" ++ show (Data.Unique.hashUnique u)
startVar <- mkVar "start" <$> Data.Unique.newUnique
resVar <- mkVar "res" <$> Data.Unique.newUnique
endVar <- mkVar "end" <$> Data.Unique.newUnique
pure $ unlines
[ startVar ++ " <- Data.Time.getCurrentTime"
, resVar ++ "<- " ++ cmd
, endVar ++ " <- Data.Time.getCurrentTime"
, unwords ["pure", resVar, "<* (System.IO.putStrLn $ show $ Data.Time.diffUTCTime", endVar, startVar, ")"]
]
:}
:def time ghciTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment