59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package profile
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
"testing/fstest"
|
|
)
|
|
|
|
func BenchmarkProfileRepositoryLookup(b *testing.B) {
|
|
for _, size := range []int{10, 1000} {
|
|
b.Run(fmt.Sprintf("catalog-%d", size), func(b *testing.B) {
|
|
files := fstest.MapFS{
|
|
"target.yaml": profileMapFile(`
|
|
id: target
|
|
endpoint: http://localhost:8000/v1
|
|
model: target-model
|
|
extra_params:
|
|
selected: true
|
|
`),
|
|
}
|
|
metadataNames := []string{"target.yaml"}
|
|
for i := 1; i < size; i++ {
|
|
name := fmt.Sprintf("profile-%04d.yaml", i)
|
|
files[name] = profileMapFile(fmt.Sprintf(`
|
|
id: profile-%04d
|
|
endpoint: http://localhost:8000/v1
|
|
model: unrelated-model
|
|
temperature: 0.5
|
|
max_tokens: 500
|
|
extra_params:
|
|
provider:
|
|
order:
|
|
- first
|
|
- second
|
|
`, i))
|
|
metadataNames = append(metadataNames, name)
|
|
}
|
|
|
|
fsys := &recordingProfileFS{FS: files}
|
|
repo := NewFSRepository(fsys, ".")
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
if _, err := repo.GetProfile(context.Background(), "target"); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
b.StopTimer()
|
|
|
|
for _, name := range metadataNames {
|
|
if got := fsys.openCount(name); got != b.N {
|
|
b.Fatalf("metadata %q opens = %d, want %d", name, got, b.N)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|