Skip to content

Commit cf002ed

Browse files
committed
WIP
1 parent 47b6ba7 commit cf002ed

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

benchmarks/FineGrained.hs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
module Main where
99

1010
import Control.Monad (replicateM)
11+
import Data.Bits (testBit)
1112
import qualified Data.HashMap.Strict as HM
13+
import Data.List
1214
import Key.Bytes
1315
import System.Random.Stateful
1416
import Test.Tasty.Bench
@@ -17,9 +19,9 @@ import Prelude hiding (Foldable (..), lookup)
1719
main :: IO ()
1820
main =
1921
defaultMain
20-
[ bFromList
21-
-- bgroup "insert" bInsert
22-
, bUnion
22+
[ bFromList,
23+
-- bgroup "insert" bInsert
24+
bUnion
2325
]
2426

2527
defaultGen :: StdGen
@@ -64,17 +66,24 @@ bUnion :: Benchmark
6466
bUnion =
6567
bgroup
6668
"union"
67-
[ bgroup "disjoint" bUnionDisjoint, bgroup "overlap" [], bgroup "same" [] ]
69+
[bgroup "disjoint" bUnionDisjoint, bgroup "overlap" [], bgroup "same" []]
6870

6971
bUnionDisjoint :: [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

7988
genInts ::
8089
(StatefulGen g m) =>

benchmarks/Key/Bytes.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
module Key.Bytes where
44

5-
import Data.List
5+
import Control.DeepSeq
66
import Control.Monad (replicateM)
77
import Data.ByteString.Short
88
import Data.Hashable
9+
import Data.List
910
import System.Random.Stateful
10-
import Control.DeepSeq
1111

1212
newtype Bytes = Bytes {unBytes :: ShortByteString}
1313
deriving (Eq, Hashable, Show, NFData)
@@ -32,12 +32,15 @@ genNBytes n len = replicateM n . genBytes len
3232
genDisjoint ::
3333
(StatefulGen g m) =>
3434
Int ->
35-
Int -> -- ^ Must be positive
35+
-- | Must be positive
36+
Int ->
3637
g ->
3738
m ([Bytes], [Bytes])
3839
genDisjoint n len gen = Data.List.partition predicate <$> genNBytes n len gen
39-
where predicate (Bytes sbs) = even (Data.ByteString.Short.head sbs)
40+
where
41+
predicate (Bytes sbs) = even (Data.ByteString.Short.head sbs)
42+
4043
{-
4144
instance Uniform Bytes where
42-
uniformM = genBytes 32
45+
uniformM = genBytes 32
4346
-}

0 commit comments

Comments
 (0)