-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from input-output-hk/jdral/compact-index-bench…
…marks Micro-benchmarks for `CompactIndex`
- Loading branch information
Showing
8 changed files
with
274 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
bench/micro/Bench/Database/LSMTree/Internal/Run/Index/Compact.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{-# LANGUAGE NumericUnderscores #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{- HLINT ignore "Eta reduce" -} | ||
|
||
module Bench.Database.LSMTree.Internal.Run.Index.Compact (benchmarks) where | ||
|
||
import Control.DeepSeq (deepseq) | ||
import Criterion.Main | ||
import Data.Foldable (Foldable (..)) | ||
import qualified Data.List.NonEmpty as NonEmpty | ||
import Database.LSMTree.Generators | ||
import Database.LSMTree.Internal.Run.Index.Compact | ||
import Database.LSMTree.Internal.Serialise (Serialise (serialise), | ||
SerialisedKey) | ||
import System.Random | ||
import System.Random.Extras | ||
|
||
-- See 'utxoNumPages'. | ||
benchmarks :: Benchmark | ||
benchmarks = bgroup "Bench.Database.LSMTree.Internal.Run.Index.Compact" [ | ||
bgroup "searches" [ | ||
env (searchEnv 0 100 2_500_000 1_000_000) $ \ ~(ci, ks) -> | ||
bench "searches with 0-bit rfprec" $ whnf (searches ci) ks | ||
, env (searchEnv 16 100 2_500_000 1_000_000) $ \ ~(ci, ks) -> | ||
bench "searches with 16-bit rfprec" $ whnf (searches ci) ks | ||
] | ||
, bgroup "construction" [ | ||
env (constructionEnv 0 2_500_000) $ \ pages -> | ||
bench "construction with 0-bit rfprec and chunk size 100" $ whnf (constructCompactIndex 100) pages | ||
, env (constructionEnv 16 2_500_000) $ \ pages -> | ||
bench "construction with 16-bit rfprec and chunk size 100" $ whnf (constructCompactIndex 100) pages | ||
] | ||
] | ||
|
||
-- | Input environment for benchmarking 'searches'. | ||
searchEnv :: | ||
RFPrecision -- ^ Range-finder bit-precision | ||
-> ChunkSize | ||
-> Int -- ^ Number of pages | ||
-> Int -- ^ Number of searches | ||
-> IO (CompactIndex, [SerialisedKey]) | ||
searchEnv fpr csize npages nsearches = do | ||
ci <- constructCompactIndex csize <$> constructionEnv fpr npages | ||
stdgen <- newStdGen | ||
let ks = serialise <$> uniformWithReplacement @UTxOKey stdgen nsearches | ||
pure (ci, ks) | ||
|
||
-- | Used for benchmarking 'search'. | ||
searches :: | ||
CompactIndex | ||
-> [SerialisedKey] -- ^ Keys to search for | ||
-> () | ||
searches ci ks = foldl' (\acc k -> search k ci `deepseq` acc) () ks | ||
|
||
-- | Input environment for benchmarking 'constructCompactIndex'. | ||
constructionEnv :: | ||
RFPrecision -- ^ Range-finder bit-precision | ||
-> Int -- ^ Number of pages | ||
-> IO (Pages SerialisedKey) | ||
constructionEnv rfprec n = do | ||
stdgen <- newStdGen | ||
let ks = uniformWithoutReplacement @UTxOKey stdgen (2 * n) | ||
pure $ serialise <$> mkPages rfprec (NonEmpty.fromList ks) | ||
|
||
-- | Used for benchmarking the incremental construction of a 'CompactIndex'. | ||
constructCompactIndex :: | ||
ChunkSize | ||
-> Pages SerialisedKey -- ^ Pages to add in succession | ||
-> CompactIndex | ||
constructCompactIndex (ChunkSize csize) (Pages (RFPrecision rfprec) ks) = | ||
-- under the hood, 'fromList' uses the incremental construction interface | ||
fromList rfprec csize ks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.