Skip to content

Commit

Permalink
Add GHC generics support everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
bos committed Apr 14, 2013
1 parent 972d9a4 commit e41298e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
15 changes: 8 additions & 7 deletions Criterion/Analysis/Types.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, RecordWildCards #-}
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, OverloadedStrings,
RecordWildCards #-}
-- |
-- Module : Criterion.Analysis.Types
-- Copyright : (c) 2011 Bryan O'Sullivan
Expand All @@ -19,10 +20,10 @@ module Criterion.Analysis.Types
) where

import Control.DeepSeq (NFData(rnf))
import Data.Data (Data)
import Data.Data (Data, Typeable)
import Data.Int (Int64)
import Data.Monoid (Monoid(..))
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import qualified Statistics.Resampling.Bootstrap as B

-- | Outliers from sample data, calculated using the boxplot
Expand All @@ -38,7 +39,7 @@ data Outliers = Outliers {
-- ^ Between 1.5 and 3 times the IQR above the third quartile.
, highSevere :: {-# UNPACK #-} !Int64
-- ^ More than 3 times the IQR above the third quartile.
} deriving (Eq, Read, Show, Typeable, Data)
} deriving (Eq, Read, Show, Typeable, Data, Generic)

instance NFData Outliers

Expand All @@ -49,7 +50,7 @@ data OutlierEffect = Unaffected -- ^ Less than 1% effect.
| Moderate -- ^ Between 10% and 50%.
| Severe -- ^ Above 50% (i.e. measurements
-- are useless).
deriving (Eq, Ord, Read, Show, Typeable, Data)
deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)

instance NFData OutlierEffect

Expand All @@ -71,7 +72,7 @@ data OutlierVariance = OutlierVariance {
-- ^ Brief textual description of effect.
, ovFraction :: Double
-- ^ Quantitative description of effect (a fraction between 0 and 1).
} deriving (Eq, Read, Show, Typeable, Data)
} deriving (Eq, Read, Show, Typeable, Data, Generic)

instance NFData OutlierVariance where
rnf OutlierVariance{..} = rnf ovEffect `seq` rnf ovDesc `seq` rnf ovFraction
Expand All @@ -81,7 +82,7 @@ data SampleAnalysis = SampleAnalysis {
anMean :: B.Estimate
, anStdDev :: B.Estimate
, anOutlierVar :: OutlierVariance
} deriving (Eq, Show, Typeable, Data)
} deriving (Eq, Read, Show, Typeable, Data, Generic)

instance NFData SampleAnalysis where
rnf SampleAnalysis{..} =
Expand Down
17 changes: 10 additions & 7 deletions Criterion/Config.hs
@@ -1,4 +1,4 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}

-- |
-- Module : Criterion.Config
Expand All @@ -22,26 +22,29 @@ module Criterion.Config
, ljust
) where

import Data.Data (Data)
import Data.Data (Data, Typeable)
import Data.Function (on)
import Data.Monoid (Monoid(..), Last(..))
import Data.Typeable (Typeable)
import GHC.Generics (Generic)

data MatchType = Prefix | Glob
deriving (Eq, Ord, Bounded, Enum, Read, Show, Typeable)
deriving (Eq, Ord, Bounded, Enum, Read, Show, Typeable, Data,
Generic)

-- | Control the amount of information displayed.
data Verbosity = Quiet
| Normal
| Verbose
deriving (Eq, Ord, Bounded, Enum, Read, Show, Typeable)
deriving (Eq, Ord, Bounded, Enum, Read, Show, Typeable, Data,
Generic)

-- | Print some information and exit, without running any benchmarks.
data PrintExit = Nada -- ^ Do not actually print-and-exit. (Default.)
| List -- ^ Print a list of known benchmarks.
| Version -- ^ Print version information (if known).
| Help -- ^ Print a help\/usaage message.
deriving (Eq, Ord, Bounded, Enum, Read, Show, Typeable, Data)
deriving (Eq, Ord, Bounded, Enum, Read, Show, Typeable, Data,
Generic)

instance Monoid PrintExit where
mempty = Nada
Expand All @@ -63,7 +66,7 @@ data Config = Config {
, cfgVerbosity :: Last Verbosity -- ^ Whether to run verbosely.
, cfgJUnitFile :: Last FilePath -- ^ Filename of JUnit report.
, cfgMeasure :: Last Bool -- ^ Whether to do any measurement.
} deriving (Eq, Read, Show, Typeable)
} deriving (Eq, Read, Show, Typeable, Generic)

instance Monoid Config where
mempty = emptyConfig
Expand Down
7 changes: 4 additions & 3 deletions Criterion/Environment.hs
@@ -1,4 +1,4 @@
{-# LANGUAGE DeriveDataTypeable, TypeOperators #-}
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, TypeOperators #-}

-- |
-- Module : Criterion.Environment
Expand All @@ -24,15 +24,16 @@ import Criterion.IO (note)
import Criterion.Measurement (getTime, runForAtLeast, time_)
import Criterion.Monad (Criterion)
import qualified Data.Vector.Unboxed as U
import Data.Typeable (Typeable)
import Data.Data (Data, Typeable)
import GHC.Generics (Generic)

-- | Measured aspects of the execution environment.
data Environment = Environment {
envClockResolution :: {-# UNPACK #-} !Double
-- ^ Clock resolution (in seconds).
, envClockCost :: {-# UNPACK #-} !Double
-- ^ The cost of a single clock call (in seconds).
} deriving (Eq, Read, Show, Typeable)
} deriving (Eq, Read, Show, Typeable, Data, Generic)

-- | Measure the execution environment.
measureEnvironment :: Criterion Environment
Expand Down
6 changes: 5 additions & 1 deletion Criterion/Internal.hs
@@ -1,4 +1,4 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, RecordWildCards #-}
-- |
-- Module : Criterion
-- Copyright : (c) 2009, 2010, 2011 Bryan O'Sullivan
Expand Down Expand Up @@ -29,6 +29,7 @@ module Criterion.Internal

import Control.Monad (replicateM_, when, mplus)
import Control.Monad.Trans (liftIO)
import Data.Data (Data, Typeable)
import Criterion.Analysis (Outliers(..), OutlierEffect(..), OutlierVariance(..),
SampleAnalysis(..), analyseSample,
classifyOutliers, noteOutliers)
Expand All @@ -42,6 +43,7 @@ import Criterion.Types (Benchmarkable(..), Benchmark(..), Pure,
bench, bgroup, nf, nfIO, whnf, whnfIO)
import qualified Data.Vector.Unboxed as U
import Data.Monoid (getLast)
import GHC.Generics (Generic)
import Statistics.Resampling.Bootstrap (Estimate(..))
import Statistics.Types (Sample)
import System.Mem (performGC)
Expand Down Expand Up @@ -120,9 +122,11 @@ data Result = Result { description :: String
, sampleAnalysis :: SampleAnalysis
, _outliers :: Outliers
}
deriving (Eq, Read, Show, Typeable, Data, Generic)

type ResultForest = [ResultTree]
data ResultTree = Single Result | Compare ResultForest
deriving (Eq, Read, Show, Typeable, Data, Generic)

-- | Run, and analyse, one or more benchmarks.
runAndAnalyse :: (String -> Bool) -- ^ A predicate that chooses
Expand Down
9 changes: 5 additions & 4 deletions Criterion/Report.hs
@@ -1,5 +1,5 @@
{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, RecordWildCards,
ScopedTypeVariables #-}
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, OverloadedStrings,
RecordWildCards, ScopedTypeVariables #-}

-- |
-- Module : Criterion.Report
Expand Down Expand Up @@ -34,6 +34,7 @@ import Criterion.Config (cfgReport, cfgTemplate, fromLJ)
import Criterion.Monad (Criterion, getConfig)
import Data.Data (Data, Typeable)
import Data.Monoid (Last(..))
import GHC.Generics (Generic)
import Paths_criterion (getDataFileName)
import Statistics.Sample.KernelDensity (kde)
import Statistics.Types (Sample)
Expand All @@ -55,7 +56,7 @@ data Report = Report {
, reportTimes :: Sample
, reportAnalysis :: SampleAnalysis
, reportOutliers :: Outliers
} deriving (Eq, Show, Typeable, Data)
} deriving (Eq, Read, Show, Typeable, Data, Generic)

-- | The path to the template and other files used for generating
-- reports.
Expand Down Expand Up @@ -163,7 +164,7 @@ includeFile searchPath name = liftIO $ foldr go (return B.empty) searchPath
-- | A problem arose with a template.
data TemplateException =
TemplateNotFound FilePath -- ^ The template could not be found.
deriving (Eq, Show, Typeable, Data)
deriving (Eq, Read, Show, Typeable, Data, Generic)

instance Exception TemplateException

Expand Down
4 changes: 2 additions & 2 deletions criterion.cabal
@@ -1,5 +1,5 @@
name: criterion
version: 0.7.0.0
version: 0.7.1.0
synopsis: Robust, reliable performance measurement and analysis
license: BSD3
license-file: LICENSE
Expand Down Expand Up @@ -67,7 +67,7 @@ library
mtl >= 2,
mwc-random >= 0.8.0.3,
parsec >= 3.1.0,
statistics >= 0.10.0.0,
statistics >= 0.10.4.0,
time,
transformers,
vector >= 0.7.1,
Expand Down

0 comments on commit e41298e

Please sign in to comment.