diff --git a/bench/Bench.hs b/bench/Bench.hs index 93f615b..630b068 100644 --- a/bench/Bench.hs +++ b/bench/Bench.hs @@ -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") - ] \ No newline at end of file + defaultMain groups \ No newline at end of file diff --git a/src/Days/D05.hs b/src/Days/D05.hs index 9873755..189333d 100644 --- a/src/Days/D05.hs +++ b/src/Days/D05.hs @@ -71,4 +71,7 @@ part2 :: Intermediate -> Vector Char part2 = uncurry ((fmap head .) . foldl (move CM9001)) day :: Day -day = parsecDay parser (definitive . part1, definitive . part2) \ No newline at end of file +day = parsecDay parser (definitive . part1, definitive . part2) + +fast :: Day +fast = day \ No newline at end of file diff --git a/src/Lib.hs b/src/Lib.hs index e1214bd..5e7da87 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -30,5 +30,5 @@ days = , [D02.day] , [D03.day] , [D04.day] - , [D05.day] + , [D05.day, D05.fast] ]