Measure delivery output and version costs

This commit is contained in:
2026-10-09 01:11:07 +00:00
parent 29e1bab228
commit 41e58ef894
5 changed files with 506 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
package gotool
import (
"bytes"
"io"
"testing"
)
const performanceDiagnosticSize = 8 << 20
func BenchmarkPerformanceCombinedOutput(b *testing.B) {
for _, testCase := range []struct {
name string
size int
}{
{name: "modest", size: 4 << 10},
{name: "diagnostic-8MiB", size: performanceDiagnosticSize},
} {
input := bytes.Repeat([]byte("go tool diagnostic output\n"), (testCase.size+25)/26)
input = input[:testCase.size]
b.Run(testCase.name+"/discard-forwarding", func(b *testing.B) {
b.ReportAllocs()
b.SetBytes(int64(len(input)))
b.ResetTimer()
b.ReportMetric(float64(len(input)), "bytes/op")
for i := 0; i < b.N; i++ {
writer := &combinedWriter{output: io.Discard}
if written, err := writer.Write(input); err != nil || written != len(input) {
b.Fatalf("write captured output = %d, err %v; want %d bytes", written, err, len(input))
}
captured := writer.Bytes()
if len(captured) != len(input) {
b.Fatalf("captured output = %d bytes, want %d", len(captured), len(input))
}
}
})
}
}