{-# LANGUAGE CPP #-}
module Data.Time.System
( getSystemTimeMicros
) where
import Data.Int (Int64)
#if WITH_TIME
import qualified Data.Time.Clock.POSIX (getPOSIXTime)
#else
import System.Clock (getTime, TimeSpec(..), Clock(Realtime))
#endif
getSystemTimeMicros :: IO Int64
getSystemTimeMicros :: IO Int64
getSystemTimeMicros = do
#if WITH_TIME
s <- Data.Time.Clock.POSIX.getPOSIXTime
return $ round $ s * 1000000
#else
TimeSpec Int64
s Int64
ns <- Clock -> IO TimeSpec
getTime Clock
Realtime
Int64 -> IO Int64
forall (m :: * -> *) a. Monad m => a -> m a
return (Int64 -> IO Int64) -> Int64 -> IO Int64
forall a b. (a -> b) -> a -> b
$ (Int64
s Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
* Int64
1000000) Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ (Int64
ns Int64 -> Int64 -> Int64
forall a. Integral a => a -> a -> a
`quot` Int64
1000)
#endif
{-# INLINE getSystemTimeMicros #-}