Last active
January 14, 2018 20:34
-
-
Save ilya-murzinov/3d877c9822bfdc0537e049fad99c8534 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE BangPatterns #-} | |
module Timer | |
( timer | |
, timer_ | |
) where | |
import Data.Time | |
timer :: IO a -> IO a | |
timer a = do | |
start <- getCurrentTime | |
!result <- a | |
end <- getCurrentTime | |
print (diffUTCTime end start) | |
return result | |
timer_ :: a -> IO a | |
timer_ a = timer $ return a | |
-- *Main Lib> timer $ print 42 | |
-- 42 | |
-- 0.000044s | |
-- *Main Lib > timer_ $ last [1..100000000] | |
-- 2.171535s | |
-- 100000000 | |
-- *Main Lib Timer Control.Concurrent> timer $ threadDelay 2000000 | |
-- 2.00183s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment