aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chelleport/Utils.hs')
-rw-r--r--src/Chelleport/Utils.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Chelleport/Utils.hs b/src/Chelleport/Utils.hs
index 0e7dabc..c15a3e8 100644
--- a/src/Chelleport/Utils.hs
+++ b/src/Chelleport/Utils.hs
@@ -1,6 +1,9 @@
module Chelleport.Utils where
+import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.List (nub)
+import Data.Time.Clock.System (SystemTime (systemNanoseconds), getSystemTime)
+import qualified Debug.Trace as Debug
import Foreign.C (CInt)
intToCInt :: Int -> CInt
@@ -24,3 +27,11 @@ isEmpty = null
isNotEmpty :: [a] -> Bool
isNotEmpty = not . isEmpty
+
+benchmark :: (MonadIO m) => String -> m a -> m a
+benchmark msg m = do
+ start <- systemNanoseconds <$> liftIO getSystemTime
+ result <- m
+ end <- systemNanoseconds <$> liftIO getSystemTime
+ Debug.traceM $ msg ++ " (ms): " ++ show (fromIntegral (end - start) / 1_000_000.0 :: Double)
+ pure result