MCPcopy Index your code
hub / github.com/coder/coder / BenchmarkDeltaUpdate

Function BenchmarkDeltaUpdate

agent/filefinder/bench_test.go:195–234  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

193}
194
195func BenchmarkDeltaUpdate(b *testing.B) {
196 dir := b.TempDir()
197 generateFileTree(b, dir, 10_000, 42)
198
199 addCounts := []int{1, 10, 100}
200
201 for _, count := range addCounts {
202 b.Run(fmt.Sprintf("add_%d_files", count), func(b *testing.B) {
203 paths := make([]string, count)
204 for i := range paths {
205 paths[i] = fmt.Sprintf("injected/dir_%d/newfile_%d.go", i%10, i)
206 }
207 b.ResetTimer()
208 for i := 0; i < b.N; i++ {
209 b.StopTimer()
210 idx := buildIndex(b, dir)
211 b.StartTimer()
212 for _, p := range paths {
213 idx.Add(p, 0)
214 }
215 }
216 b.ReportMetric(float64(count), "files_added/op")
217 })
218 }
219
220 b.Run("search_after_100_additions", func(b *testing.B) {
221 idx := buildIndex(b, dir)
222 for i := 0; i < 100; i++ {
223 idx.Add(fmt.Sprintf("injected/extra/file_%d.go", i), 0)
224 }
225 snap := idx.Snapshot()
226 plan := filefinder.NewQueryPlanForTest("handler")
227 opts := filefinder.DefaultSearchOptions()
228
229 b.ResetTimer()
230 for i := 0; i < b.N; i++ {
231 _ = filefinder.SearchSnapshotForTest(plan, snap, opts.MaxCandidates)
232 }
233 })
234}
235
236func BenchmarkMemoryProfile(b *testing.B) {
237 scales := []struct {

Callers

nothing calls this directly

Calls 7

DefaultSearchOptionsFunction · 0.92
generateFileTreeFunction · 0.85
buildIndexFunction · 0.85
SnapshotMethod · 0.80
TempDirMethod · 0.65
RunMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected