Skip to content

Instantly share code, notes, and snippets.

@ilya-murzinov
Last active January 14, 2018 20:34
Show Gist options
  • Save ilya-murzinov/3d877c9822bfdc0537e049fad99c8534 to your computer and use it in GitHub Desktop.
Save ilya-murzinov/3d877c9822bfdc0537e049fad99c8534 to your computer and use it in GitHub Desktop.
{-# 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