From 2648406b3437ec3be118922702346cb117b9c195 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 6 Jun 2016 17:15:51 -0400 Subject: [PATCH] Generalize generativeBenchmark over Gen a. --- bench/Main.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bench/Main.hs b/bench/Main.hs index 321cbfbd5..f413f0006 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -26,11 +26,14 @@ instance NFData a => NFData (Patch a) -- | -- | The inputs’ sizes at each iteration are measured by a metric function, which gives the name of the benchmark. This makes it convenient to correlate a benchmark of some function over lists with e.g. input `length`. generativeBenchmark :: (Arbitrary a, Show m, Ord m) => String -> Int -> (a -> m) -> (a -> Benchmarkable) -> IO Benchmark -generativeBenchmark name n metric benchmark = do +generativeBenchmark name n metric benchmark = generativeBenchmarkWith name n arbitrary metric benchmark + +generativeBenchmarkWith :: (Show m, Ord m) => String -> Int -> Gen a -> (a -> m) -> (a -> Benchmarkable) -> IO Benchmark +generativeBenchmarkWith name n generator metric benchmark = do benchmarks <- traverse measure (replicate n defaultSize) pure $! bgroup name (snd <$> (sortOn fst benchmarks)) where measure n = do - input <- generate (resize n arbitrary) + input <- generate (resize n generator) let measurement = metric input pure $! (measurement, bench (show measurement) (benchmark input)) defaultSize = 100