timeit-2.0/0000755000000000000000000000000013242776162011046 5ustar0000000000000000timeit-2.0/CHANGELOG.md0000644000000000000000000000015513242776162012660 0ustar00000000000000002.0 --- * Generalise `timeIt` and `timeItT` to work for any `MonadIO` * Added `timeItShow` and `timeItNamed` timeit-2.0/LICENSE0000644000000000000000000000277613242776162012067 0ustar0000000000000000Copyright (c) 2009, Lennart Augustsson All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Merijn Verstraaten nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. timeit-2.0/Setup.hs0000644000000000000000000000010013242776162012471 0ustar0000000000000000module Main where import Distribution.Simple main = defaultMain timeit-2.0/timeit.cabal0000644000000000000000000000217613242776162013333 0ustar0000000000000000Name: timeit Version: 2.0 Homepage: https://github.com/merijn/timeit Bug-Reports: https://github.com/merijn/timeit/issues Author: Lennart Augustsson Maintainer: Merijn Verstraaten , Lennart Augustsson Copyright: Copyright © 2009, Lennart Augustsson License: BSD3 License-File: LICENSE Category: System Cabal-Version: >= 1.10 Build-Type: Simple Tested-With: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.1, GHC == 8.5.* Extra-Source-Files: CHANGELOG.md Synopsis: Time monadic computations with an IO base. Description: A simple wrapper to show the used CPU time of monadic computation with an IO base. Library Default-Language: Haskell2010 GHC-Options: -Wall Exposed-Modules: System.TimeIt Build-Depends: base >= 3 && < 5 if impl(ghc < 8.0) Build-Depends: transformers >= 0.2 && < 0.6 Source-Repository head Type: git Location: ssh://github.com:merijn/broadcast-chan.git timeit-2.0/System/0000755000000000000000000000000013242776162012332 5ustar0000000000000000timeit-2.0/System/TimeIt.hs0000644000000000000000000000214513242776162014063 0ustar0000000000000000module System.TimeIt(timeIt, timeItShow, timeItNamed, timeItT) where import System.CPUTime import Text.Printf import Control.Monad.IO.Class (MonadIO(liftIO)) -- | Wrap a 'MonadIO' computation so that it prints out the execution time. timeIt :: MonadIO m => m a -> m a timeIt = timeItNamed "CPU time" -- | Like 'timeIt', but uses the 'show' rendering of @a@ as label for the -- timing. -- -- @since 2.0 timeItShow :: (MonadIO m, Show a) => m a -> m a timeItShow ioa = do (t, a) <- timeItT ioa liftIO $ printf (show a ++ ": %6.2fs\n") t return a -- | Like 'timeIt', but uses the 'String' as label for the timing. -- -- @since 2.0 timeItNamed :: MonadIO m => String -> m a -> m a timeItNamed name ioa = do (t, a) <- timeItT ioa liftIO $ printf (name ++ ": %6.2fs\n") t return a -- | Wrap a 'MonadIO' computation so that it returns execution time in seconds, -- as well as the result value. timeItT :: MonadIO m => m a -> m (Double, a) timeItT ioa = do t1 <- liftIO getCPUTime a <- ioa t2 <- liftIO getCPUTime let t :: Double t = fromIntegral (t2-t1) * 1e-12 return (t, a)