Attempt to set up benchmark

This commit is contained in:
ctsk
2023-08-30 13:30:36 +02:00
parent 5796db3249
commit 69dbc4e001
3 changed files with 38 additions and 7 deletions

View File

@@ -1,9 +1,37 @@
module Main where
import Criterion (bench, whnfIO)
import Criterion.Main (defaultMain)
import Lib
import Criterion
import Criterion.Main
paths :: [FilePath]
paths =
[ "./data/01.in"
, "./data/02.in"
, "./data/03.in"
, "./data/04.in"
, "./data/05.in"
]
solutions :: [(Integer, [Day], FilePath)]
solutions = filter (\(n, d, p) -> length d > 1) $ zip3 [1 ..] days paths
makeGroup :: (Show a) => (a, [Day], FilePath) -> Benchmark
makeGroup (n, d, f) =
bgroup ("Day " ++ show n) (makeBenchmarks f d)
makeBenchmarks :: FilePath -> [Day] -> [Benchmark]
makeBenchmarks f = zipWith name [1 ..] . map (makeBench f)
where
name :: Int -> Benchmarkable -> Benchmark
name n = bench ("v" ++ show n)
makeBench :: FilePath -> Day -> Benchmarkable
makeBench f d = nfAppIO (fmap show . run d) f
groups :: [Benchmark]
groups = map makeGroup solutions
main =
defaultMain
[ bench "whnfIO readFile" $ whnfIO (readFile "Y2022.cabal")
]
defaultMain groups