Skip to content

Commit 0de947c

Browse files
committed
WIP
1 parent 50c77fd commit 0de947c

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

benchmarks/FineGrained.hs

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

1010
import Control.Monad (replicateM)
11-
import qualified Data.HashMap.Internal as HMI
1211
import qualified Data.HashMap.Strict as HM
13-
import Data.Hashable (Hashable, hash)
1412
import Key.Bytes
1513
import System.Random.Stateful
1614
import Test.Tasty.Bench
@@ -21,7 +19,7 @@ main =
2119
defaultMain
2220
[ bFromList
2321
-- bgroup "insert" bInsert
24-
-- union
22+
, bUnion
2523
]
2624

2725
defaultGen :: StdGen
@@ -30,26 +28,8 @@ defaultGen = mkStdGen 42
3028
defaultSizes :: [Int]
3129
defaultSizes = [0, 1, 10, 100, 1000, 10_000, 100_000]
3230

33-
{-
34-
bInsert = [ env m $ \d -> bench (show s) $ whnf (\(k, v, m) -> HM.insert k v m) d ]
35-
where m s = do
36-
g <- newIOGenM defaultGen
37-
let hm = HM.empty
38-
forM_ [1..s] $ \v -> do
39-
b <- genBytes 32 g
40-
HMI.unsafeInsert b v hm
41-
return (m, newKeys) -- separate existing, new
42-
-}
43-
44-
{-
45-
matrix :: (NFData env) => [Int] -> (Int -> IO env) -> (env -> Benchmarkable) -> Benchmark
46-
matrix sizes e x = b -- [ b @Bytes, b @Int] -- , b @SlowInt, b @Colli ]
47-
where
48-
b = bgroup "bla" [runTemplate @Int e x s | s <- sizes]
49-
50-
runTemplate :: forall env. (NFData env) => (Int -> IO env) -> (env -> Benchmarkable) -> Int -> Benchmark
51-
runTemplate e b s = env (e s) $ \x -> bench (show s) (b x)
52-
-}
31+
bytesLength :: Int
32+
bytesLength = 32
5333

5434
bFromList :: Benchmark
5535
bFromList =
@@ -60,10 +40,10 @@ bFromList =
6040
[ env
6141
( do
6242
g <- newIOGenM defaultGen
63-
genNBytes s 32 g
43+
genNBytes s bytesLength g
6444
)
6545
$ \keys ->
66-
bench (show s) $ whnf (HM.fromList . map (, ())) keys
46+
bench (show s) $ whnf (HM.fromList . map (,())) keys
6747
| s <- sizes
6848
],
6949
bgroup
@@ -80,6 +60,22 @@ bFromList =
8060
where
8161
sizes = defaultSizes
8262

63+
bUnion :: Benchmark
64+
bUnion =
65+
bgroup
66+
"union"
67+
[ bgroup "disjoint" bUnionDisjoint, bgroup "overlap" [], bgroup "same" [] ]
68+
69+
bUnionDisjoint :: [Benchmark]
70+
bUnionDisjoint = [bgroup "Bytes" [], bgroup "Int" []]
71+
where
72+
bytesEnv s = do
73+
g <- newIOGenM defaultGen
74+
trues <- undefined s
75+
falses <- undefined s
76+
return (map (,()) trues, map (,()) falses)
77+
78+
8379
genInts ::
8480
(StatefulGen g m) =>
8581
Int ->
@@ -94,3 +90,24 @@ bFromList = matrix defaultSizes e' b'
9490
e' s = uniformListM s defaultGen
9591
b' = whnf HM.fromList
9692
-}
93+
94+
{-
95+
bInsert = [ env m $ \d -> bench (show s) $ whnf (\(k, v, m) -> HM.insert k v m) d ]
96+
where m s = do
97+
g <- newIOGenM defaultGen
98+
let hm = HM.empty
99+
forM_ [1..s] $ \v -> do
100+
b <- genBytes 32 g
101+
HMI.unsafeInsert b v hm
102+
return (m, newKeys) -- separate existing, new
103+
-}
104+
105+
{-
106+
matrix :: (NFData env) => [Int] -> (Int -> IO env) -> (env -> Benchmarkable) -> Benchmark
107+
matrix sizes e x = b -- [ b @Bytes, b @Int] -- , b @SlowInt, b @Colli ]
108+
where
109+
b = bgroup "bla" [runTemplate @Int e x s | s <- sizes]
110+
111+
runTemplate :: forall env. (NFData env) => (Int -> IO env) -> (env -> Benchmarkable) -> Int -> Benchmark
112+
runTemplate e b s = env (e s) $ \x -> bench (show s) (b x)
113+
-}

benchmarks/Key/Bytes.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,14 @@ genNBytes ::
2626
m [Bytes]
2727
genNBytes n len = replicateM n . genBytes len
2828

29+
genDisjoint ::
30+
(StatefulGen g m) =>
31+
Int ->
32+
Int ->
33+
g ->
34+
m ([Bytes], [Bytes])
35+
genDisjoint n len = undefined
36+
{-
2937
instance Uniform Bytes where
3038
uniformM = genBytes 32
39+
-}

0 commit comments

Comments
 (0)