diff --git a/internal/bytesconv/bytesconv_timing_test.go b/internal/bytesconv/bytesconv_timing_test.go new file mode 100644 index 000000000..4e0e27ba9 --- /dev/null +++ b/internal/bytesconv/bytesconv_timing_test.go @@ -0,0 +1,36 @@ +package bytesconv + +import ( + "golang.org/x/net/http/httpguts" + "testing" +) + +func BenchmarkValidHeaderFiledValueTable(b *testing.B) { + // Test all characters + allBytes := make([]string, 0) + for i := 0; i < 256; i++ { + allBytes = append(allBytes, string([]byte{byte(i)})) + } + + for i := 0; i < b.N; i++ { + for _, s := range allBytes { + _ = httpguts.ValidHeaderFieldValue(s) + } + } +} + +func BenchmarkValidHeaderFiledValueTableHertz(b *testing.B) { + // Test all characters + allBytes := make([]byte, 0) + for i := 0; i < 256; i++ { + allBytes = append(allBytes, byte(i)) + } + + for i := 0; i < b.N; i++ { + for _, s := range allBytes { + _ = func() bool { + return ValidHeaderFieldValueTable[s] != 0 + }() + } + } +}