Commits

Bryan O'Sullivan  committed d1e86d4

Add an nfIO function.

  • Participants
  • Parent commits 9a7a1b3

Comments (0)

Files changed (4)

File Criterion.hs

     , Benchmark
     , Pure
     , nf
+    , nfIO
     , whnf
     , bench
     , bgroup
 import Criterion.Monad (Criterion, getConfig, getConfigItem)
 import Criterion.Plot (plotWith, plotKDE, plotTiming)
 import Criterion.Types (Benchmarkable(..), Benchmark(..), Pure,
-                        bench, bgroup, nf, whnf)
+                        bench, bgroup, nf, nfIO, whnf)
 import Data.Array.Vector ((:*:)(..), concatU, lengthU, mapU)
 import Statistics.Function (createIO, minMax)
 import Statistics.KernelDensity (epanechnikovPDF)

File Criterion/Main.hs

     , bench
     , bgroup
     , nf
+    , nfIO
     , whnf
     -- * Running benchmarks
     , defaultMain
 import Criterion.MultiMap (singleton)
 import Criterion.Monad (Criterion, withConfig)
 import Criterion.Types (Benchmarkable(..), Benchmark(..), Pure, bench,
-                        benchNames, bgroup, nf, whnf)
+                        benchNames, bgroup, nf, nfIO, whnf)
 import Data.List (isPrefixOf, sort)
 import Data.Monoid (Monoid(..), Last(..))
 import System.Console.GetOpt

File Criterion/Types.hs

     , Pure
     , whnf
     , nf
+    , nfIO
     , bench
     , bgroup
     , benchNames
     WHNF :: (a -> b) -> a -> Pure
     NF :: NFData b => (a -> b) -> a -> Pure
 
+-- | Apply an argument to a function, and evaluate the result to weak
+-- head normal form (WHNF).
 whnf :: (a -> b) -> a -> Pure
 whnf = WHNF
 {-# INLINE whnf #-}
 
+-- | Apply an argument to a function, and evaluate the result to head
+-- normal form (NF).
 nf :: NFData b => (a -> b) -> a -> Pure
 nf = NF
 {-# INLINE nf #-}
 
+-- | Perform an action, then evaluate its result to head normal form.
+-- This is particularly useful for forcing a lazy IO action to be
+-- completely performed.
+nfIO :: NFData a => IO a -> IO ()
+nfIO a = a >>= \k -> return $! rnf k
+{-# INLINE nfIO #-}
+
 instance Benchmarkable Pure where
     run p@(WHNF _ _) = go p
       where

File criterion.cabal

 name:           criterion
-version:        0.4.0
+version:        0.4.1.0
 synopsis:       Robust, reliable performance measurement and analysis
 license:        BSD3
 license-file:   LICENSE