Last active
March 13, 2024 14:57
-
-
Save ramirez7/a63610820d9636a11925b68b6991ec6b to your computer and use it in GitHub Desktop.
Get the _real_ time of stuff in ghci
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
:{ | |
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