MCPcopy Index your code
hub / github.com/nutsdb/nutsdb / BenchmarkIterator_PartialScan

Function BenchmarkIterator_PartialScan

iterator_bench_test.go:301–338  ·  view source on GitHub ↗

BenchmarkIterator_PartialScan tests scanning a portion of data

(b *testing.B)

Source from the content-addressed store, hash-verified

299
300// BenchmarkIterator_PartialScan tests scanning a portion of data
301func BenchmarkIterator_PartialScan(b *testing.B) {
302 db, bucket := setupIteratorBenchmark(b, 100000)
303 defer func() { _ = db.Close() }()
304
305 b.ResetTimer()
306 b.ReportAllocs()
307
308 for i := 0; i < b.N; i++ {
309 err := db.View(func(tx *Tx) error {
310 iterator := NewIterator(tx, bucket, IteratorOptions{Reverse: false})
311 defer iterator.Release()
312
313 // Seek to starting position
314 startKey := testutils.GetTestBytes(10000)
315 if !iterator.Seek(startKey) {
316 return fmt.Errorf("seek failed")
317 }
318
319 // Scan 1000 items
320 count := 0
321 for iterator.Valid() && count < 1000 {
322 _ = iterator.Key()
323 _, err := iterator.Value()
324 if err != nil {
325 return err
326 }
327 count++
328 if !iterator.Next() {
329 break
330 }
331 }
332 return nil
333 })
334 if err != nil {
335 b.Fatalf("View failed: %v", err)
336 }
337 }
338}
339
340// BenchmarkIterator_ValidCheck tests Valid() method overhead
341func BenchmarkIterator_ValidCheck(b *testing.B) {

Callers

nothing calls this directly

Calls 11

ReleaseMethod · 0.95
SeekMethod · 0.95
ValidMethod · 0.95
KeyMethod · 0.95
ValueMethod · 0.95
NextMethod · 0.95
GetTestBytesFunction · 0.92
setupIteratorBenchmarkFunction · 0.85
NewIteratorFunction · 0.85
ViewMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected