timeit 1.0.0.0 → 2.0
raw patch · 4 files changed
+102/−22 lines, 4 filesdep +transformersdep ~basenew-uploader
Dependencies added: transformers
Dependency ranges changed: base
Files
- CHANGELOG.md +4/−0
- LICENSE +30/−0
- System/TimeIt.hs +28/−10
- timeit.cabal +40/−12
+ CHANGELOG.md view
@@ -0,0 +1,4 @@+2.0+---+* Generalise `timeIt` and `timeItT` to work for any `MonadIO`+* Added `timeItShow` and `timeItNamed`
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (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.
System/TimeIt.hs view
@@ -1,20 +1,38 @@-module System.TimeIt(timeIt, timeItT) where+module System.TimeIt(timeIt, timeItShow, timeItNamed, timeItT) where import System.CPUTime import Text.Printf+import Control.Monad.IO.Class (MonadIO(liftIO)) --- |Wrap an 'IO' computation so that it prints out the execution time.-timeIt :: IO a -> IO a-timeIt ioa = do+-- | 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- printf "CPU time: %6.2fs\n" t+ liftIO $ printf (show a ++ ": %6.2fs\n") t return a --- |Wrap an 'IO' computation so that it returns execution time is seconds as well as the real value.-timeItT :: IO a -> IO (Double, 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 <- getCPUTime+ t1 <- liftIO getCPUTime a <- ioa- t2 <- getCPUTime+ t2 <- liftIO getCPUTime let t :: Double- t = fromIntegral (t2-t1) * 1e-12+ t = fromIntegral (t2-t1) * 1e-12 return (t, a)
timeit.cabal view
@@ -1,12 +1,40 @@-Name: timeit-Version: 1.0.0.0-License: BSD3-Author: Lennart Augustsson-Maintainer: Lennart Augustsson-Category: System-Synopsis: Time a computation-Description: A simple wrapper of an IO computation to show the used CPU time.-Build-type: Simple-Build-Depends: base-Exposed-modules: System.TimeIt-build-depends: base >= 3 && < 5+Name: timeit+Version: 2.0++Homepage: https://github.com/merijn/timeit+Bug-Reports: https://github.com/merijn/timeit/issues++Author: Lennart Augustsson+Maintainer: Merijn Verstraaten <merijn@inconsistent.nl>, 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