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

Function BenchmarkHintFileRead

hintfile_bench_test.go:129–198  ·  view source on GitHub ↗

BenchmarkHintFileRead benchmarks reading hint entries from file

(b *testing.B)

Source from the content-addressed store, hash-verified

127
128// BenchmarkHintFileRead benchmarks reading hint entries from file
129func BenchmarkHintFileRead(b *testing.B) {
130 tmpDir, err := os.MkdirTemp("", "hintfile-bench-read")
131 if err != nil {
132 b.Fatalf("Failed to create temp dir: %v", err)
133 }
134 defer func() { _ = os.RemoveAll(tmpDir) }()
135
136 hintPath := tmpDir + "/test.hint"
137
138 // Create a hint file with 1000 entries
139 writer := &HintFileWriter{}
140 err = writer.Create(hintPath)
141 if err != nil {
142 b.Fatalf("Failed to create hint file: %v", err)
143 }
144
145 entries := make([]*HintEntry, 1000)
146 for i := 0; i < 1000; i++ {
147 entries[i] = &HintEntry{
148 BucketId: 1,
149 KeySize: 10,
150 ValueSize: 100,
151 Timestamp: uint64(time.Now().UnixMilli()),
152 TTL: 3600,
153 Flag: DataSetFlag,
154 Status: Committed,
155 Ds: DataStructureBTree,
156 DataPos: uint64(i * 10),
157 FileID: 1,
158 Key: []byte(fmt.Sprintf("key%d", i)),
159 }
160
161 err := writer.Write(entries[i])
162 if err != nil {
163 b.Fatalf("Failed to write hint entry: %v", err)
164 }
165 }
166
167 err = writer.Close()
168 if err != nil {
169 b.Fatalf("Failed to close hint file: %v", err)
170 }
171
172 b.ResetTimer()
173 for i := 0; i < b.N; i++ {
174 reader := &HintFileReader{}
175 err := reader.Open(hintPath)
176 if err != nil {
177 b.Fatalf("Failed to open hint file: %v", err)
178 }
179
180 count := 0
181 for {
182 _, err := reader.Read()
183 if err != nil {
184 break
185 }
186 count++

Callers

nothing calls this directly

Calls 6

CreateMethod · 0.95
WriteMethod · 0.95
CloseMethod · 0.95
OpenMethod · 0.95
ReadMethod · 0.95
CloseMethod · 0.95

Tested by

no test coverage detected