MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / BenchmarkMergeWithoutHintFile

Function BenchmarkMergeWithoutHintFile

hintfile_bench_test.go:401–456  ·  view source on GitHub ↗

BenchmarkMergeWithoutHintFile benchmarks merge operation without hint files enabled

(b *testing.B)

Source from the content-addressed store, hash-verified

399
400// BenchmarkMergeWithoutHintFile benchmarks merge operation without hint files enabled
401func BenchmarkMergeWithoutHintFile(b *testing.B) {
402 tmpDir, err := os.MkdirTemp("", "hintfile-bench-merge-no-hint")
403 if err != nil {
404 b.Fatalf("Failed to create temp dir: %v", err)
405 }
406 defer func() { _ = os.RemoveAll(tmpDir) }()
407
408 opts := DefaultOptions
409 opts.Dir = tmpDir
410 opts.SegmentSize = 64 * KB
411 opts.EnableHintFile = false
412
413 b.ResetTimer()
414 for i := 0; i < b.N; i++ {
415 // Create fresh database for each iteration
416 iterDir := fmt.Sprintf("%s/iter%d", tmpDir, i)
417 opts.Dir = iterDir
418
419 db, err := Open(opts)
420 if err != nil {
421 b.Fatalf("Failed to open database: %v", err)
422 }
423
424 bucket := "bucket"
425 txCreateBucket(&testing.T{}, db, DataStructureBTree, bucket, nil)
426
427 // Add data and delete some to trigger merge
428 for j := 0; j < 2000; j++ {
429 txPut(&testing.T{}, db, bucket, testutils.GetTestBytes(j), testutils.GetTestBytes(j), Persistent, nil, nil)
430 }
431
432 for j := 0; j < 500; j++ {
433 txDel(&testing.T{}, db, bucket, testutils.GetTestBytes(j), nil)
434 }
435
436 // Perform merge without hint file creation
437 b.StopTimer()
438 start := time.Now()
439 b.StartTimer()
440
441 err = db.Merge()
442 if err != nil {
443 b.Fatalf("Failed to merge: %v", err)
444 }
445
446 b.StopTimer()
447 mergeTime := time.Since(start)
448 b.ReportMetric(float64(mergeTime.Nanoseconds())/1e6, "ms")
449 b.StartTimer()
450
451 err = db.Close()
452 if err != nil {
453 b.Fatalf("Failed to close database: %v", err)
454 }
455 }
456}
457
458// BenchmarkHintFileLoad benchmarks loading hint files during database startup

Callers

nothing calls this directly

Calls 7

GetTestBytesFunction · 0.92
OpenFunction · 0.85
txCreateBucketFunction · 0.85
txPutFunction · 0.85
txDelFunction · 0.85
MergeMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected