|
| 1 | +{-# LANGUAGE DeriveAnyClass #-} |
| 2 | +{-# LANGUAGE DeriveGeneric #-} |
| 3 | +{-# LANGUAGE ImportQualifiedPost #-} |
| 4 | +{-# LANGUAGE NumericUnderscores #-} |
| 5 | +{-# LANGUAGE TypeApplications #-} |
| 6 | + |
| 7 | +-- | This module contains benchmarks for Peras Object diffusion decision logic |
| 8 | +-- as implemented by the by the function |
| 9 | +-- 'Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Inbound.V2.Decision.makeDecision' |
| 10 | +module Main (main) where |
| 11 | + |
| 12 | +import Control.DeepSeq (NFData (..)) |
| 13 | +import Control.Exception (evaluate) |
| 14 | +import Data.Hashable (Hashable) |
| 15 | +import GHC.Generics (Generic) |
| 16 | +import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Inbound.V2.Decision qualified as OD |
| 17 | +import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Inbound.V2.TestUtils qualified as OD |
| 18 | +import Test.QuickCheck (Arbitrary (..), generate) |
| 19 | +import Test.QuickCheck.Gen (vectorOf) |
| 20 | +import Test.Tasty.Bench |
| 21 | + |
| 22 | +-- TODO: We will probably want to use the actual types used in vote/cert diffusion, |
| 23 | +-- instead of placeholders. |
| 24 | +newtype DummyPeerAddr = DummyPeerAddr Int |
| 25 | + deriving (Eq, Ord, Generic, NFData) |
| 26 | + |
| 27 | +instance Arbitrary DummyPeerAddr where |
| 28 | + arbitrary = DummyPeerAddr <$> arbitrary |
| 29 | + |
| 30 | +newtype DummyObjectId = DummyObjectId Int |
| 31 | + deriving (Eq, Ord, Generic, Hashable, NFData) |
| 32 | + |
| 33 | +instance Arbitrary DummyObjectId where |
| 34 | + arbitrary = DummyObjectId <$> arbitrary |
| 35 | + |
| 36 | +data DummyObject = DummyObject |
| 37 | + { doId :: DummyObjectId |
| 38 | + , doPayload :: () |
| 39 | + } |
| 40 | + deriving (Eq, Ord, Generic, Hashable, NFData) |
| 41 | + |
| 42 | +instance Arbitrary DummyObject where |
| 43 | + arbitrary = DummyObject <$> arbitrary <*> arbitrary |
| 44 | + |
| 45 | +-- TODO: We should probably use specific policies that are well suited to the |
| 46 | +-- number of peers and objects. |
| 47 | + |
| 48 | +main :: IO () |
| 49 | +main = |
| 50 | + defaultMain |
| 51 | + [ bgroup |
| 52 | + "ouroboros-consensus:ObjectDiffusion" |
| 53 | + [ bgroup |
| 54 | + "VoteDiffusion" |
| 55 | + [ env |
| 56 | + (genToNF $ vectorOf 1_000 $ OD.genDecisionContext 10 50 doId Nothing) |
| 57 | + ( \contexts -> |
| 58 | + bench "makeDecisions: 1000 decisions with (10 pairs, 50 objects) each" $ |
| 59 | + nf (fmap makeVoteDiffusionDecisions) contexts |
| 60 | + ) |
| 61 | + , env |
| 62 | + (genToNF $ vectorOf 1_000 $ OD.genDecisionContext 100 500 doId Nothing) |
| 63 | + ( \contexts -> |
| 64 | + bench "makeDecisions: 1000 decisions with (100 pairs, 500 objects) each" $ |
| 65 | + nf (fmap makeVoteDiffusionDecisions) contexts |
| 66 | + ) |
| 67 | + , env |
| 68 | + (genToNF $ vectorOf 1_000 $ OD.genDecisionContext 1_000 5_000 doId Nothing) |
| 69 | + ( \contexts -> |
| 70 | + bench "makeDecisions: 1000 decisions with (1000 pairs, 5000 objects) each" $ |
| 71 | + nf (fmap makeVoteDiffusionDecisions) contexts |
| 72 | + ) |
| 73 | + ] |
| 74 | + , bgroup "CertDiffusion" [] |
| 75 | + ] |
| 76 | + ] |
| 77 | + where |
| 78 | + genToNF gen = do |
| 79 | + x <- generate gen |
| 80 | + evaluate $ rnf x |
| 81 | + pure $! x |
| 82 | + |
| 83 | + makeVoteDiffusionDecisions decisionContext = |
| 84 | + OD.makeDecisions @DummyPeerAddr @DummyObjectId @DummyObject decisionContext |
0 commit comments