88module Main where
99
1010import Control.Monad (replicateM )
11+ import Data.Bits (testBit )
1112import qualified Data.HashMap.Strict as HM
13+ import Data.List
1214import Key.Bytes
1315import System.Random.Stateful
1416import Test.Tasty.Bench
@@ -17,9 +19,9 @@ import Prelude hiding (Foldable (..), lookup)
1719main :: IO ()
1820main =
1921 defaultMain
20- [ bFromList
21- -- bgroup "insert" bInsert
22- , bUnion
22+ [ bFromList,
23+ -- bgroup "insert" bInsert
24+ bUnion
2325 ]
2426
2527defaultGen :: StdGen
@@ -64,17 +66,24 @@ bUnion :: Benchmark
6466bUnion =
6567 bgroup
6668 " union"
67- [ bgroup " disjoint" bUnionDisjoint, bgroup " overlap" [] , bgroup " same" [] ]
69+ [bgroup " disjoint" bUnionDisjoint, bgroup " overlap" [] , bgroup " same" [] ]
6870
6971bUnionDisjoint :: [Benchmark ]
70- bUnionDisjoint = [bgroup " Bytes" [env (bytesEnv s) (bytesB s) | s <- defaultSizes], bgroup " Int" [] ]
72+ bUnionDisjoint =
73+ [ bgroup " Bytes" [env (bytesEnv s) (bench' s) | s <- defaultSizes],
74+ bgroup " Int" [env (intsEnv s) (bench' s) | s <- defaultSizes]
75+ ]
7176 where
72- bytesB s tup = bench (show s) $ whnf (\ ~ (as, bs) -> HM. union as bs) tup
77+ bench' s tup = bench (show s) $ whnf (\ (as, bs) -> HM. union as bs) tup
7378 bytesEnv s = do
7479 g <- newIOGenM defaultGen
7580 (trues, falses) <- Key.Bytes. genDisjoint s bytesLength g
7681 return (HM. fromList (map (,() ) trues), HM. fromList (map (,() ) falses))
77-
82+ intsEnv s = do
83+ g <- newIOGenM defaultGen
84+ ints <- genInts s g
85+ let (trues, falses) = Data.List. partition (flip testBit (31 :: Int )) ints
86+ return (HM. fromList (map (,() ) trues), HM. fromList (map (,() ) falses))
7887
7988genInts ::
8089 (StatefulGen g m ) =>
0 commit comments