tinyrelayfile
tinyrelay/tinyclient/source_benchmark_test.go/

tinyclient/source_benchmark_test.go raw
1package tinyclient
2
3import (
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.
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 int
20 for b.Loop() {
21 size = len(sourceHTML(value))
22 }
23 b.ReportMetric(float64(size), "rendered-bytes")
24 })
25 }
26}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs