| 1 | package usagecatalog |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | func BenchmarkWarmQueryTenYears(b *testing.B) { |
| 12 | catalog, err := Open(context.Background(), filepath.Join(b.TempDir(), "usage.sqlite")) |
| 13 | if err != nil { |
| 14 | b.Fatal(err) |
| 15 | } |
| 16 | b.Cleanup(func() { _ = catalog.Close(context.Background()) }) |
| 17 | tx, err := catalog.db.Begin() |
| 18 | if err != nil { |
| 19 | b.Fatal(err) |
| 20 | } |
| 21 | start := time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC) |
| 22 | for day := range 3_650 { |
| 23 | date := start.AddDate(0, 0, day).Format("2006-01-02") |
| 24 | for model := range 8 { |
| 25 | ref := fmt.Sprintf("provider/model-%d", model) |
| 26 | if _, err := tx.Exec(`INSERT INTO usage_rollups(day,source,model_ref,provider,prompt,completion,reasoning,cache_hit,cache_miss,total,requests,turns) |
| 27 | VALUES(?,?,?,?,1,1,0,0,1,2,1,1)`, date, "desktop", ref, "provider"); err != nil { |
| 28 | b.Fatal(err) |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | if err := tx.Commit(); err != nil { |
| 33 | b.Fatal(err) |
| 34 | } |
| 35 | b.ResetTimer() |
| 36 | for range b.N { |
| 37 | if _, err := catalog.Query(context.Background(), "2016-01-01", "2025-12-28", "all"); err != nil { |
| 38 | b.Fatal(err) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 |