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

Function BenchmarkHintFileWrite

hintfile_bench_test.go:74–126  ·  view source on GitHub ↗

BenchmarkHintFileWrite benchmarks writing hint entries to file

(b *testing.B)

Source from the content-addressed store, hash-verified

72
73// BenchmarkHintFileWrite benchmarks writing hint entries to file
74func BenchmarkHintFileWrite(b *testing.B) {
75 tmpDir, err := os.MkdirTemp("", "hintfile-bench-write")
76 if err != nil {
77 b.Fatalf("Failed to create temp dir: %v", err)
78 }
79 defer func() {
80 if err := os.RemoveAll(tmpDir); err != nil {
81 b.Errorf("Failed to remove temp dir: %v", err)
82 }
83 }()
84
85 hintPath := tmpDir + "/test.hint"
86
87 entries := make([]*HintEntry, 1000)
88 for i := 0; i < 1000; i++ {
89 entries[i] = &HintEntry{
90 BucketId: 1,
91 KeySize: 10,
92 ValueSize: 100,
93 Timestamp: uint64(time.Now().UnixMilli()),
94 TTL: 3600,
95 Flag: DataSetFlag,
96 Status: Committed,
97 Ds: DataStructureBTree,
98 DataPos: uint64(i * 10),
99 FileID: 1,
100 Key: []byte(fmt.Sprintf("key%d", i)),
101 }
102 }
103
104 b.ResetTimer()
105 for i := 0; i < b.N; i++ {
106 writer := &HintFileWriter{}
107 err := writer.Create(hintPath)
108 if err != nil {
109 b.Fatalf("Failed to create hint file: %v", err)
110 }
111
112 for _, entry := range entries {
113 err := writer.Write(entry)
114 if err != nil {
115 b.Fatalf("Failed to write hint entry: %v", err)
116 }
117 }
118
119 err = writer.Close()
120 if err != nil {
121 b.Fatalf("Failed to close hint file: %v", err)
122 }
123
124 _ = os.Remove(hintPath)
125 }
126}
127
128// BenchmarkHintFileRead benchmarks reading hint entries from file
129func BenchmarkHintFileRead(b *testing.B) {

Callers

nothing calls this directly

Calls 4

CreateMethod · 0.95
WriteMethod · 0.95
CloseMethod · 0.95
RemoveMethod · 0.45

Tested by

no test coverage detected