@@ -31,6 +31,7 @@ benchmarks :: Benchmark
3131benchmarks = bgroup " Bench.Database.LSMTree.Normal" [
3232 benchLargeValueVsSmallValueBlob
3333 , benchCursorScanVsRangeLookupScan
34+ , benchInsertBatches
3435 ]
3536
3637{- ------------------------------------------------------------------------------
@@ -215,6 +216,50 @@ benchCursorScanVsRangeLookupScan =
215216 Normal. closeSession s
216217 cleanupFiles (tmpDir, hfs, hbio)
217218
219+
220+ {- ------------------------------------------------------------------------------
221+ Benchmark batches of inserts
222+ -------------------------------------------------------------------------------}
223+
224+ benchInsertBatches :: Benchmark
225+ benchInsertBatches =
226+ env genInserts $ \ iss ->
227+ withEnv $ \ ~ (_, _, _, _, t :: Normal. Table IO Word64 Word64 Void ) -> do
228+ bench " benchInsertBatches" $ whnfIO $
229+ V. mapM_ (flip Normal. inserts t) iss
230+ where
231+ ! initialSize = 100_000
232+ ! batchSize = 256
233+
234+ _benchConfig :: Common. TableConfig
235+ _benchConfig = Common. defaultTableConfig {
236+ Common. confWriteBufferAlloc = Common. AllocNumEntries (Common. NumEntries 1000 )
237+ }
238+
239+ randomInserts :: Int -> V. Vector (Word64 , Word64 , Maybe Void )
240+ randomInserts n = V. unfoldrExactN n f (mkStdGen 17 )
241+ where f ! g = let (! k, ! g') = uniform g
242+ in ((k, v, Nothing ), g')
243+ -- The exact value does not matter much, so we pick an arbitrary
244+ -- hardcoded one.
245+ ! v = 17
246+
247+ genInserts :: IO (V. Vector (V. Vector (Word64 , Word64 , Maybe Void )))
248+ genInserts = pure $ vgroupsOfN batchSize $ randomInserts initialSize
249+
250+ withEnv = envWithCleanup initialise cleanup
251+
252+ initialise = do
253+ (tmpDir, hfs, hbio) <- mkFiles
254+ s <- Normal. openSession nullTracer hfs hbio (FS. mkFsPath [] )
255+ t <- Normal. new s _benchConfig
256+ pure (tmpDir, hfs, hbio, s, t)
257+
258+ cleanup (tmpDir, hfs, hbio, s, t) = do
259+ Normal. close t
260+ Normal. closeSession s
261+ cleanupFiles (tmpDir, hfs, hbio)
262+
218263{- ------------------------------------------------------------------------------
219264 Setup
220265-------------------------------------------------------------------------------}
0 commit comments