1package tinyclient23import (4 "strings"5 "testing"6)78// Keep source previews inexpensive even when a small file contains very many9// lines. Rendered bytes matter here as well as server time and allocations.10func 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 int20 for b.Loop() {21 size = len(sourceHTML(value))22 }23 b.ReportMetric(float64(size), "rendered-bytes")24 })25 }26}