(b *testing.B)
| 234 | } |
| 235 | |
| 236 | func BenchmarkMemoryProfile(b *testing.B) { |
| 237 | scales := []struct { |
| 238 | name string |
| 239 | n int |
| 240 | }{ |
| 241 | {"10K", 10_000}, |
| 242 | {"100K", 100_000}, |
| 243 | } |
| 244 | |
| 245 | for _, sc := range scales { |
| 246 | b.Run(sc.name, func(b *testing.B) { |
| 247 | if sc.n >= 100_000 && testing.Short() { |
| 248 | b.Skip("skipping large-scale memory profile") |
| 249 | } |
| 250 | dir := b.TempDir() |
| 251 | generateFileTree(b, dir, sc.n, 42) |
| 252 | |
| 253 | b.ResetTimer() |
| 254 | for i := 0; i < b.N; i++ { |
| 255 | idx := buildIndex(b, dir) |
| 256 | _ = idx.Snapshot() |
| 257 | } |
| 258 | b.StopTimer() |
| 259 | |
| 260 | // Report memory stats on the last iteration. |
| 261 | runtime.GC() |
| 262 | var before runtime.MemStats |
| 263 | runtime.ReadMemStats(&before) |
| 264 | idx := buildIndex(b, dir) |
| 265 | var after runtime.MemStats |
| 266 | runtime.ReadMemStats(&after) |
| 267 | |
| 268 | allocDelta := after.TotalAlloc - before.TotalAlloc |
| 269 | b.ReportMetric(float64(allocDelta)/float64(idx.Len()), "bytes/file") |
| 270 | |
| 271 | runtime.GC() |
| 272 | runtime.ReadMemStats(&before) |
| 273 | snap := idx.Snapshot() |
| 274 | _ = snap |
| 275 | runtime.GC() |
| 276 | runtime.ReadMemStats(&after) |
| 277 | |
| 278 | snapAlloc := after.TotalAlloc - before.TotalAlloc |
| 279 | b.ReportMetric(float64(snapAlloc)/float64(idx.Len()), "snap-bytes/file") |
| 280 | }) |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | func BenchmarkSearch_ConcurrentReads_Throughput(b *testing.B) { |
| 285 | dir := b.TempDir() |
nothing calls this directly
no test coverage detected