diff --git a/src/Test/Tasty/Bench/Equalize.hs b/src/Test/Tasty/Bench/Equalize.hs index 413a9b3..9cc1e6a 100644 --- a/src/Test/Tasty/Bench/Equalize.hs +++ b/src/Test/Tasty/Bench/Equalize.hs @@ -1,8 +1,8 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE NumDecimals #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} +-- | Find a tipping point between two algorithms. module Test.Tasty.Bench.Equalize ( equalize, mkEqualizeConfig, @@ -13,27 +13,31 @@ import Control.DeepSeq (NFData) import System.IO.Unsafe (unsafeInterleaveIO) import Test.Tasty (Timeout (..)) import Test.Tasty.Bench (Benchmarkable, RelStDev (..), measureCpuTimeAndStDev, nf) +import Test.Tasty.Bench.Utils (traceShowM') -#ifdef DEBUG -import Debug.Trace -#endif - --- | Configuration for 'fit'. +-- | Configuration for 'equalize'. data EqualizeConfig = EqualizeConfig { eqlFasterOnLow :: Word -> Benchmarkable + -- ^ A benchmark which is faster at 'eqlLow', typically 'nf' @f@. , eqlFasterOnHigh :: Word -> Benchmarkable + -- ^ A benchmark which is faster at 'eqlHigh', typically 'nf' @g@. , eqlLow :: Word + -- ^ An argument at which 'eqlFasterOnLow' is faster than 'eqlFasterOnHigh'. , eqlHigh :: Word + -- ^ An argument at which 'eqlFasterOnHigh' is faster than 'eqlFasterOnLow'. , eqlTimeout :: Timeout + -- ^ Timeout of individual measurements. } -- | Generate a default 'equalize' configuration. mkEqualizeConfig :: (NFData a) => (Word -> a) + -- ^ An algorithm which is faster for small arguments, without 'nf'. -> (Word -> a) + -- ^ An algorithm which is faster for large arguments, without 'nf'. -> (Word, Word) - -- ^ The smallest and the largest sizes of the input. + -- ^ A small and a large arguments. -> EqualizeConfig mkEqualizeConfig fLow fHigh (low, high) = EqualizeConfig @@ -64,10 +68,3 @@ equalize EqualizeConfig {..} = go (RelStDev 1.0) eqlLow eqlHigh if mean2 + 2 * stdev2 < mean1 - 2 * stdev1 then go std lo mid else go (RelStDev $ std' / 2) lo hi - -traceShowM' :: (Applicative m, Show a) => a -> m () -#ifdef DEBUG -traceShowM' = traceShowM -#else -traceShowM' = const (pure ()) -#endif diff --git a/src/Test/Tasty/Bench/Fit.hs b/src/Test/Tasty/Bench/Fit.hs index e628a74..7c86978 100644 --- a/src/Test/Tasty/Bench/Fit.hs +++ b/src/Test/Tasty/Bench/Fit.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE NumDecimals #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -48,10 +47,7 @@ import Test.Tasty.Bench.Fit.Complexity ( isLogarithmic, isQuadratic, ) - -#ifdef DEBUG -import Debug.Trace -#endif +import Test.Tasty.Bench.Utils (traceShowM') -- | Configuration for 'fit'. data FitConfig = FitConfig @@ -200,10 +196,3 @@ fits FitConfig {..} = unsafeInterleaveIO $ do d :: Word -> Double d = fromIntegral - -traceShowM' :: (Applicative m, Show a) => a -> m () -#ifdef DEBUG -traceShowM' = traceShowM -#else -traceShowM' = const (pure ()) -#endif diff --git a/tasty-bench-fit.cabal b/tasty-bench-fit.cabal index 11134ef..43cf7f9 100644 --- a/tasty-bench-fit.cabal +++ b/tasty-bench-fit.cabal @@ -36,7 +36,10 @@ library Test.Tasty.Bench.Equalize hs-source-dirs: src - other-modules: Test.Tasty.Bench.Fit.Complexity + other-modules: + Test.Tasty.Bench.Fit.Complexity + Test.Tasty.Bench.Utils + default-language: Haskell2010 ghc-options: -Wall build-depends: