Skip to content

Commit

Permalink
test: add benchmark for ValidHeaderFieldValueTable
Browse files Browse the repository at this point in the history
  • Loading branch information
welkeyever committed Jan 2, 2024
1 parent 48d0422 commit 410aa0d
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions internal/bytesconv/bytesconv_timing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2024 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package bytesconv

import (
"testing"

"golang.org/x/net/http/httpguts"
)

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
}()
}
}
}

0 comments on commit 410aa0d

Please sign in to comment.