Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Jun 18, 2024
1 parent 75ccd6c commit 1a43f95
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
25 changes: 11 additions & 14 deletions src/Test/Tasty/Bench/Equalize.hs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
13 changes: 1 addition & 12 deletions src/Test/Tasty/Bench/Fit.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion tasty-bench-fit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1a43f95

Please sign in to comment.