@@ -11,7 +11,8 @@ import Bench.Consensus.Mempool
1111import Bench.Consensus.Mempool.TestBlock (TestBlock )
1212import qualified Bench.Consensus.Mempool.TestBlock as TestBlock
1313import Control.Arrow (first )
14- import Control.Monad (unless , void )
14+ import Control.DeepSeq
15+ import Control.Monad (unless )
1516import qualified Control.Tracer as Tracer
1617import Data.Aeson
1718import qualified Data.ByteString.Lazy as BL
@@ -27,7 +28,7 @@ import qualified Test.Consensus.Mempool.Mocked as Mocked
2728import Test.Consensus.Mempool.Mocked (MockedMempool )
2829import Test.Tasty (withResource )
2930import Test.Tasty.Bench (CsvPath (CsvPath ), bench , benchIngredients ,
30- bgroup , nfIO )
31+ bgroup , whnfIO )
3132import Test.Tasty.HUnit (testCase , (@?=) )
3233import Test.Tasty.Options (changeOption )
3334import Test.Tasty.Runners (parseOptions , tryIngredients )
@@ -50,24 +51,27 @@ main = withStdTerminalHandles $ do
5051 where
5152 benchmarkJustAddingTransactions =
5253 bgroup " Just adding" $
53- fmap benchAddNTxs [10_000 , 1_000_000 ]
54+ fmap benchAddNTxs [10_000 , 20_000 ]
5455 where
5556 benchAddNTxs n =
5657 withResource
57- (let txs = mkNTryAddTxs n in fmap (, txs) (openMempoolWithCapacityFor txs) )
58+ (pure $!! mkNTryAddTxs n)
5859 (\ _ -> pure () )
59- (\ getAcquiredRes -> do
60- let withAcquiredMempool act = do
61- (mempool, txs) <- getAcquiredRes
62- void $ act mempool txs
63- -- TODO: consider adding a 'reset' command to the mempool to make sure its state is not tainted.
64- Mocked. removeTxs mempool $ getCmdsTxIds txs
60+ (\ getTxs -> do
6561 bgroup (show n <> " transactions" ) [
66- bench " benchmark" $ nfIO $ withAcquiredMempool $ \ mempool txs -> do
62+ bench " setup mempool" $ whnfIO $ do
63+ txs <- getTxs
64+ openMempoolWithCapacityFor txs
65+ , bench " setup mempool + benchmark" $ whnfIO $ do
66+ txs <- getTxs
67+ mempool <- openMempoolWithCapacityFor txs
6768 run mempool txs
68- , testCase " test" $ withAcquiredMempool $ \ mempool txs ->
69+ , testCase " test" $ do
70+ txs <- getTxs
71+ mempool <- openMempoolWithCapacityFor txs
6972 testAddTxs mempool txs
70- , testCase " txs length" $ withAcquiredMempool $ \ _mempool txs -> do
73+ , testCase " txs length" $ do
74+ txs <- getTxs
7175 length txs @?= n
7276 ]
7377 )
0 commit comments