module Main (main) where
import Breadth.B4 qualified as Breadth4
import Breadth.B16 qualified as Breadth16
import Breadth.B64 qualified as Breadth64
import Depth.D1 qualified as Depth1
import Depth.D2 qualified as Depth2
import Depth.D4 qualified as Depth4
import Depth.D8 qualified as Depth8
import Data.Foldable (foldl', toList)
import Test.Tasty.Bench
main :: IO ()
main = defaultMain
[ bgroup "breadth"
[ bgroup "4" $ cases Breadth4.indices
, bgroup "16" $ cases Breadth16.indices
, bgroup "64" $ cases Breadth64.indices
]
, bgroup "depth"
[ bgroup "1" $ cases Depth1.indices
, bgroup "2" $ cases Depth2.indices
, bgroup "4" $ cases Depth4.indices
, bgroup "8" $ cases Depth8.indices
]
]
cases :: forall f t. (Foldable f, Enum t) => f t -> [Benchmark]
cases collection =
[ bench "fromEnum" $ whnf (foldl' (\acc t -> acc + fromEnum t) 0) tags
, bench "toEnum" $ whnf (foldl' (\acc i -> toEnum @t i `seq` acc + 1) (0 :: Int)) ints
]
where
tags = toList collection
ints = [0 .. length tags - 1]