Skip to content

Commit

Permalink
Add an nfIO function.
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : 88459844b44422256ae6f934cb0a50a0ff0bbbc8
  • Loading branch information
bos committed Dec 15, 2009
1 parent 23cb612 commit 7a164ad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Criterion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Criterion
, Benchmark
, Pure
, nf
, nfIO
, whnf
, bench
, bgroup
Expand All @@ -33,7 +34,7 @@ import Criterion.Measurement (getTime, runForAtLeast, secs, time_)
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)
Expand Down
3 changes: 2 additions & 1 deletion Criterion/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Criterion.Main
, bench
, bgroup
, nf
, nfIO
, whnf
-- * Running benchmarks
, defaultMain
Expand All @@ -50,7 +51,7 @@ import Criterion.IO (note, printError)
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
Expand Down
12 changes: 12 additions & 0 deletions Criterion/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module Criterion.Types
, Pure
, whnf
, nf
, nfIO
, bench
, bgroup
, benchNames
Expand All @@ -52,14 +53,25 @@ data Pure where
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
Expand Down
2 changes: 1 addition & 1 deletion criterion.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: criterion
version: 0.4.0
version: 0.4.1.0
synopsis: Robust, reliable performance measurement and analysis
license: BSD3
license-file: LICENSE
Expand Down

0 comments on commit 7a164ad

Please sign in to comment.