Measure delivery output and version costs
This commit is contained in:
38
internal/gotool/performance_test.go
Normal file
38
internal/gotool/performance_test.go
Normal 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))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user