aboutsummaryrefslogtreecommitdiff
path: root/header_timing_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'header_timing_test.go')
-rw-r--r--header_timing_test.go46
1 files changed, 39 insertions, 7 deletions
diff --git a/header_timing_test.go b/header_timing_test.go
index 0d7ab67..81ff7fb 100644
--- a/header_timing_test.go
+++ b/header_timing_test.go
@@ -12,6 +12,9 @@ import (
var strFoobar = []byte("foobar.com")
+// it has the same length as Content-Type
+var strNonSpecialHeader = []byte("Dontent-Type")
+
type benchReadBuf struct {
s []byte
n int
@@ -96,12 +99,13 @@ func BenchmarkResponseHeaderWrite(b *testing.B) {
})
}
-func BenchmarkRequestHeaderPeekBytesCanonical(b *testing.B) {
+// Result: 2.2 ns/op
+func BenchmarkRequestHeaderPeekBytesSpecialHeader(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var h RequestHeader
- h.SetBytesV("Host", strFoobar)
+ h.SetContentTypeBytes(strFoobar)
for pb.Next() {
- v := h.PeekBytes(strHost)
+ v := h.PeekBytes(strContentType)
if !bytes.Equal(v, strFoobar) {
b.Fatalf("unexpected result: %q. Expected %q", v, strFoobar)
}
@@ -109,13 +113,41 @@ func BenchmarkRequestHeaderPeekBytesCanonical(b *testing.B) {
})
}
-func BenchmarkRequestHeaderPeekBytesNonCanonical(b *testing.B) {
+// Result: 2.9 ns/op
+func BenchmarkRequestHeaderPeekBytesNonSpecialHeader(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var h RequestHeader
- h.SetBytesV("Host", strFoobar)
- hostBytes := []byte("HOST")
+ h.SetBytesKV(strNonSpecialHeader, strFoobar)
+ for pb.Next() {
+ v := h.PeekBytes(strNonSpecialHeader)
+ if !bytes.Equal(v, strFoobar) {
+ b.Fatalf("unexpected result: %q. Expected %q", v, strFoobar)
+ }
+ }
+ })
+}
+
+// Result: 2.3 ns/op
+func BenchmarkResponseHeaderPeekBytesSpecialHeader(b *testing.B) {
+ b.RunParallel(func(pb *testing.PB) {
+ var h ResponseHeader
+ h.SetContentTypeBytes(strFoobar)
+ for pb.Next() {
+ v := h.PeekBytes(strContentType)
+ if !bytes.Equal(v, strFoobar) {
+ b.Fatalf("unexpected result: %q. Expected %q", v, strFoobar)
+ }
+ }
+ })
+}
+
+// Result: 2.9 ns/op
+func BenchmarkResponseHeaderPeekBytesNonSpecialHeader(b *testing.B) {
+ b.RunParallel(func(pb *testing.PB) {
+ var h ResponseHeader
+ h.SetBytesKV(strNonSpecialHeader, strFoobar)
for pb.Next() {
- v := h.PeekBytes(hostBytes)
+ v := h.PeekBytes(strNonSpecialHeader)
if !bytes.Equal(v, strFoobar) {
b.Fatalf("unexpected result: %q. Expected %q", v, strFoobar)
}