Timing.hs revision 41582f75931338095dc749c455593c859376d593
55cf6e01272ec475edea32aa9b7923de2d36cb42Christian Maeder{-# LANGUAGE CPP #-}
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova{- |
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaModule : $Header$
b43458b4d81f7451112cecbd757f3a05216e7088Kristina SojakovaDescription : utility module for measuring execution time
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaCopyright : (c) C. Maeder DFKI GmbH
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaMaintainer : Christian.Maeder@dfki.de
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaStability : provisional
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaPortability : portable
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaUtility functions that can't be found in the libraries
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova but should be shared across Hets.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova-}
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovamodule Common.Timing where
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova
b2e01ef1b5d4c7a62260eb792291e8e1b10e545bIulia Ignatov#ifdef UNIX
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovaimport System.Posix.Time
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovaimport System.Posix.Types
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakova#else
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovaimport Data.Time.Clock
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova#endif
44e934cd533a334ae00a65b83dba146c1352b0aaIulia Ignatov
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovaimport Data.Time
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovaimport Control.Monad
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova#ifdef UNIX
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakovanewtype HetsTime = HetsTime EpochTime
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova#else
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovanewtype HetsTime = HetsTime UTCTime
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder#endif
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovagetHetsTime :: IO HetsTime
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovagetHetsTime = liftM HetsTime
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova#ifdef UNIX
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova epochTime
b43458b4d81f7451112cecbd757f3a05216e7088Kristina Sojakova#else
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova getCurrentTime
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova#endif
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovadiffHetsTime :: HetsTime -> HetsTime -> TimeOfDay
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovadiffHetsTime (HetsTime t1) (HetsTime t2) =
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova timeToTimeOfDay $ secondsToDiffTime $ round
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova (realToFrac (
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder#ifdef UNIX
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder (-)
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder#else
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder diffUTCTime
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova#endif
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova t1 t2) :: Double)
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova