test(ermitegit): add cold and parallel variants to the routing benchmarks
- commit
- 38230d3f4a9a8f222deedb65412a2d08e0a86793
- author
- brice · · 2026-10-11 00:46 UTC
- parent
- dbef343
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +34 -1
M internal/adapters/ermitegit/bench_test.go +34 -1
| @@ -182,12 +182,21 @@ func BenchmarkRepoReader(b *testing.B) { | |||
| 182 | 182 | return | |
| 183 | 183 | }}, | |
| 184 | 184 | } | |
| 185 | + | // Each method runs three ways, for both readers: warm (the repository is | |
| 186 | + | // open, one caller), cold (the repository is closed before every call: the | |
| 187 | + | // price of the first read after the idle TTL, an eviction or a restart) and | |
| 188 | + | // parallel (b.RunParallel: the contention of the cache and of the library). | |
| 189 | + | // The CLI reader keeps no repository open, so its cold run is its warm run. | |
| 185 | 190 | for _, m := range methods { | |
| 186 | 191 | b.Run(m.name, func(b *testing.B) { | |
| 187 | 192 | for _, ad := range []struct { | |
| 188 | 193 | name string | |
| 189 | 194 | r ports.RepoReader | |
| 190 | - | }{{"cli", g}, {"ermitegit", a}} { | |
| 195 | + | cold func() // closes what the reader holds open | |
| 196 | + | }{ | |
| 197 | + | {"cli", g, func() {}}, | |
| 198 | + | {"ermitegit", a, func() { a.Forget(t.dir) }}, | |
| 199 | + | } { | |
| 191 | 200 | b.Run(ad.name, func(b *testing.B) { | |
| 192 | 201 | require.NoError(b, m.run(ad.r)) // warm-up: processes, caches, graph | |
| 193 | 202 | b.ReportAllocs() | |
| @@ -198,6 +207,30 @@ func BenchmarkRepoReader(b *testing.B) { | |||
| 198 | 207 | } | |
| 199 | 208 | } | |
| 200 | 209 | }) | |
| 210 | + | b.Run(ad.name+"_cold", func(b *testing.B) { | |
| 211 | + | require.NoError(b, m.run(ad.r)) | |
| 212 | + | b.ReportAllocs() | |
| 213 | + | b.ResetTimer() | |
| 214 | + | for b.Loop() { | |
| 215 | + | ad.cold() | |
| 216 | + | if err := m.run(ad.r); err != nil { | |
| 217 | + | b.Fatal(err) | |
| 218 | + | } | |
| 219 | + | } | |
| 220 | + | }) | |
| 221 | + | b.Run(ad.name+"_parallel", func(b *testing.B) { | |
| 222 | + | require.NoError(b, m.run(ad.r)) | |
| 223 | + | b.ReportAllocs() | |
| 224 | + | b.ResetTimer() | |
| 225 | + | b.RunParallel(func(pb *testing.PB) { | |
| 226 | + | for pb.Next() { | |
| 227 | + | if err := m.run(ad.r); err != nil { | |
| 228 | + | b.Error(err) | |
| 229 | + | return | |
| 230 | + | } | |
| 231 | + | } | |
| 232 | + | }) | |
| 233 | + | }) | |
| 201 | 234 | } | |
| 202 | 235 | }) | |
| 203 | 236 | } | |
| @@ -182,12 +182,21 @@ func BenchmarkRepoReader(b *testing.B) { | |||||
| 182 | return | 182 | return | ||
| 183 | }}, | 183 | }}, | ||
| 184 | } | 184 | } | ||
| 185 | + | // Each method runs three ways, for both readers: warm (the repository is | |||
| 186 | + | // open, one caller), cold (the repository is closed before every call: the | |||
| 187 | + | // price of the first read after the idle TTL, an eviction or a restart) and | |||
| 188 | + | // parallel (b.RunParallel: the contention of the cache and of the library). | |||
| 189 | + | // The CLI reader keeps no repository open, so its cold run is its warm run. | |||
| 185 | for _, m := range methods { | 190 | for _, m := range methods { | ||
| 186 | b.Run(m.name, func(b *testing.B) { | 191 | b.Run(m.name, func(b *testing.B) { | ||
| 187 | for _, ad := range []struct { | 192 | for _, ad := range []struct { | ||
| 188 | name string | 193 | name string | ||
| 189 | r ports.RepoReader | 194 | r ports.RepoReader | ||
| 190 | - | }{{"cli", g}, {"ermitegit", a}} { | 195 | + | cold func() // closes what the reader holds open |
| 196 | + | }{ | |||
| 197 | + | {"cli", g, func() {}}, | |||
| 198 | + | {"ermitegit", a, func() { a.Forget(t.dir) }}, | |||
| 199 | + | } { | |||
| 191 | b.Run(ad.name, func(b *testing.B) { | 200 | b.Run(ad.name, func(b *testing.B) { | ||
| 192 | require.NoError(b, m.run(ad.r)) // warm-up: processes, caches, graph | 201 | require.NoError(b, m.run(ad.r)) // warm-up: processes, caches, graph | ||
| 193 | b.ReportAllocs() | 202 | b.ReportAllocs() | ||
| @@ -198,6 +207,30 @@ func BenchmarkRepoReader(b *testing.B) { | |||||
| 198 | } | 207 | } | ||
| 199 | } | 208 | } | ||
| 200 | }) | 209 | }) | ||
| 210 | + | b.Run(ad.name+"_cold", func(b *testing.B) { | |||
| 211 | + | require.NoError(b, m.run(ad.r)) | |||
| 212 | + | b.ReportAllocs() | |||
| 213 | + | b.ResetTimer() | |||
| 214 | + | for b.Loop() { | |||
| 215 | + | ad.cold() | |||
| 216 | + | if err := m.run(ad.r); err != nil { | |||
| 217 | + | b.Fatal(err) | |||
| 218 | + | } | |||
| 219 | + | } | |||
| 220 | + | }) | |||
| 221 | + | b.Run(ad.name+"_parallel", func(b *testing.B) { | |||
| 222 | + | require.NoError(b, m.run(ad.r)) | |||
| 223 | + | b.ReportAllocs() | |||
| 224 | + | b.ResetTimer() | |||
| 225 | + | b.RunParallel(func(pb *testing.PB) { | |||
| 226 | + | for pb.Next() { | |||
| 227 | + | if err := m.run(ad.r); err != nil { | |||
| 228 | + | b.Error(err) | |||
| 229 | + | return | |||
| 230 | + | } | |||
| 231 | + | } | |||
| 232 | + | }) | |||
| 233 | + | }) | |||
| 201 | } | 234 | } | ||
| 202 | }) | 235 | }) | ||
| 203 | } | 236 | } | ||