(b *testing.B)
| 86 | } |
| 87 | |
| 88 | func BenchmarkBuildIndex(b *testing.B) { |
| 89 | scales := []struct { |
| 90 | name string |
| 91 | n int |
| 92 | }{ |
| 93 | {"1K", 1_000}, |
| 94 | {"10K", 10_000}, |
| 95 | {"100K", 100_000}, |
| 96 | } |
| 97 | |
| 98 | for _, sc := range scales { |
| 99 | b.Run(sc.name, func(b *testing.B) { |
| 100 | if sc.n >= 100_000 && testing.Short() { |
| 101 | b.Skip("skipping large-scale benchmark") |
| 102 | } |
| 103 | dir := b.TempDir() |
| 104 | generateFileTree(b, dir, sc.n, 42) |
| 105 | |
| 106 | b.ResetTimer() |
| 107 | for i := 0; i < b.N; i++ { |
| 108 | idx := buildIndex(b, dir) |
| 109 | if idx.Len() == 0 { |
| 110 | b.Fatal("expected non-empty index") |
| 111 | } |
| 112 | } |
| 113 | b.StopTimer() |
| 114 | |
| 115 | idx := buildIndex(b, dir) |
| 116 | b.ReportMetric(float64(idx.Len())/b.Elapsed().Seconds(), "files/sec") |
| 117 | }) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func BenchmarkSearch_ByScale(b *testing.B) { |
| 122 | queries := []struct { |
nothing calls this directly
no test coverage detected