Skip to content

Commit

Permalink
martian/header: Add BenchmarkViaModifier
Browse files Browse the repository at this point in the history
benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: github.com/saucelabs/forwarder/internal/martian/header
cpu: Apple M1 Pro
            │   old.txt    │               new.txt               │
            │    sec/op    │   sec/op     vs base                │
ViaModifier   2299.0n ± 3%   154.3n ± 2%  -93.29% (p=0.000 n=10)

            │   old.txt   │              new.txt               │
            │    B/op     │    B/op     vs base                │
ViaModifier   1440.0 ± 0%   160.0 ± 0%  -88.89% (p=0.000 n=10)

            │   old.txt   │              new.txt               │
            │  allocs/op  │ allocs/op   vs base                │
ViaModifier   31.000 ± 0%   4.000 ± 0%  -87.10% (p=0.000 n=10)
  • Loading branch information
mmatczuk committed Dec 5, 2024
1 parent 871329d commit bd69ea3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/martian/header/via_modifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,22 @@ func TestViaModifier(t *testing.T) {
t.Fatalf("req.Close: got %v, want true", req.Close)
}
}

func BenchmarkViaModifier(b *testing.B) {
const via = "1.0\talpha\t(martian), 1.1 martian-boundary, 1.1 beta"

req, err := http.NewRequest(http.MethodGet, "/", http.NoBody)
if err != nil {
b.Fatalf("http.NewRequest(): got %v, want no error", err)
}

m := NewViaModifier("martian")

b.ResetTimer()
for i := 0; i < b.N; i++ {
req.Header.Set("Via", via)
if err := m.ModifyRequest(req); err != nil {
b.Fatalf("ModifyRequest(): got %v, want no error", err)
}
}
}

0 comments on commit bd69ea3

Please sign in to comment.