Skip to content

Commit ccfc73b

Browse files
committed
mempool-bench: move more pre-calculation into withResource
1 parent 2ebacd7 commit ccfc73b

File tree

1 file changed

+22
-22
lines changed
  • ouroboros-consensus/bench/mempool-bench

1 file changed

+22
-22
lines changed

ouroboros-consensus/bench/mempool-bench/Main.hs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Data.Set ()
2121
import qualified Data.Text as Text
2222
import qualified Data.Text.Read as Text.Read
2323
import Main.Utf8 (withStdTerminalHandles)
24+
import Ouroboros.Consensus.Ledger.SupportsMempool (ByteSize)
2425
import qualified Ouroboros.Consensus.Mempool.Capacity as Mempool
2526
import System.Exit (die, exitFailure)
2627
import qualified Test.Consensus.Mempool.Mocked as Mocked
@@ -54,31 +55,33 @@ main = withStdTerminalHandles $ do
5455
where
5556
benchAddNTxs n =
5657
withResource
57-
(pure $!! mkNTryAddTxs n)
58+
(pure $!!
59+
let cmds = mkNTryAddTxs n
60+
in (cmds, foldMap TestBlock.txSize $ getCmdsTxs cmds))
5861
(\_ -> pure ())
59-
(\getTxs -> do
62+
(\getCmds -> do
6063
bgroup (show n <> " transactions") [
6164
bench "setup mempool" $ whnfIO $ do
62-
txs <- getTxs
63-
openMempoolWithCapacityFor txs
65+
(_cmds, capacity) <- getCmds
66+
openMempoolWithCapacity capacity
6467
, bench "setup mempool + benchmark" $ whnfIO $ do
65-
txs <- getTxs
66-
mempool <- openMempoolWithCapacityFor txs
67-
run mempool txs
68+
(cmds, capacity) <- getCmds
69+
mempool <- openMempoolWithCapacity capacity
70+
run mempool cmds
6871
, testCase "test" $ do
69-
txs <- getTxs
70-
mempool <- openMempoolWithCapacityFor txs
71-
testAddTxs mempool txs
72-
, testCase "txs length" $ do
73-
txs <- getTxs
74-
length txs @?= n
72+
(cmds, capacity) <- getCmds
73+
mempool <- openMempoolWithCapacity capacity
74+
testAddCmds mempool cmds
75+
, testCase "cmds length" $ do
76+
(cmds, _capacity) <- getCmds
77+
length cmds @?= n
7578
]
7679
)
7780
where
78-
testAddTxs mempool txs = do
79-
run mempool txs
81+
testAddCmds mempool cmds = do
82+
run mempool cmds
8083
mempoolTxs <- Mocked.getTxs mempool
81-
mempoolTxs @?= getCmdsTxs txs
84+
mempoolTxs @?= getCmdsTxs cmds
8285

8386
parseBenchmarkResults csvFilePath = do
8487
csvData <- BL.readFile csvFilePath
@@ -129,17 +132,14 @@ main = withStdTerminalHandles $ do
129132
Adding TestBlock transactions to a mempool
130133
-------------------------------------------------------------------------------}
131134

132-
openMempoolWithCapacityFor :: [MempoolCmd TestBlock] -> IO (MockedMempool IO TestBlock)
133-
openMempoolWithCapacityFor cmds =
134-
Mocked.openMockedMempool capacityRequiredByCmds
135+
openMempoolWithCapacity :: ByteSize -> IO (MockedMempool IO TestBlock)
136+
openMempoolWithCapacity capacity =
137+
Mocked.openMockedMempool (Mempool.mkCapacityBytesOverride capacity)
135138
Tracer.nullTracer
136139
Mocked.MempoolAndModelParams {
137140
Mocked.immpInitialState = TestBlock.initialLedgerState
138141
, Mocked.immpLedgerConfig = TestBlock.sampleLedgerConfig
139142
}
140-
where
141-
capacityRequiredByCmds = Mempool.mkCapacityBytesOverride totalTxsSize
142-
where totalTxsSize = foldMap TestBlock.txSize $ getCmdsTxs cmds
143143

144144
mkNTryAddTxs :: Int -> [MempoolCmd TestBlock.TestBlock]
145145
mkNTryAddTxs 0 = []

0 commit comments

Comments
 (0)