| 1 | package tinyclient |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // Keep source previews inexpensive even when a small file contains very many |
| 9 | // lines. Rendered bytes matter here as well as server time and allocations. |
| 10 | func BenchmarkSourcePreview(b *testing.B) { |
| 11 | for _, fixture := range []struct{ name, content string }{ |
| 12 | {"go" , strings.Repeat("func main() { fmt.Println(\"hello\") }\n" , 3000)}, |
| 13 | {"short_lines" , strings.Repeat("\n" , sourcePreviewLimit)}, |
| 14 | } { |
| 15 | b.Run(fixture.name, func(b *testing.B) { |
| 16 | value := map[string]any{"path" : "main.go" , "content" : fixture.content} |
| 17 | b.ReportAllocs() |
| 18 | b.SetBytes(int64(len(fixture.content))) |
| 19 | var size int |
| 20 | for b.Loop() { |
| 21 | size = len(sourceHTML(value)) |
| 22 | } |
| 23 | b.ReportMetric(float64(size), "rendered-bytes" ) |
| 24 | }) |
| 25 | } |
| 26 | } |