Attempt to set up benchmark
This commit is contained in:
@@ -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
|
||||
@@ -72,3 +72,6 @@ part2 = uncurry ((fmap head .) . foldl (move CM9001))
|
||||
|
||||
day :: Day
|
||||
day = parsecDay parser (definitive . part1, definitive . part2)
|
||||
|
||||
fast :: Day
|
||||
fast = day
|
||||
@@ -30,5 +30,5 @@ days =
|
||||
, [D02.day]
|
||||
, [D03.day]
|
||||
, [D04.day]
|
||||
, [D05.day]
|
||||
, [D05.day, D05.fast]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user