mirror of
https://github.com/gin-gonic/gin.git
synced 2025-12-06 15:47:04 +08:00
refactor: use b.Loop() to simplify the code and improve performance (#4432)
Signed-off-by: efcking <efcking@outlook.com>
This commit is contained in:
parent
fb27ef26c2
commit
a85ef5ce4d
@ -18,9 +18,8 @@ func BenchmarkSliceValidationError(b *testing.B) {
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
if len(e.Error()) == 0 {
|
||||
b.Errorf("error")
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ type structFull struct {
|
||||
|
||||
func BenchmarkMapFormFull(b *testing.B) {
|
||||
var s structFull
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
err := mapForm(&s, form)
|
||||
if err != nil {
|
||||
b.Fatalf("Error on a form mapping")
|
||||
@ -54,7 +54,7 @@ type structName struct {
|
||||
|
||||
func BenchmarkMapFormName(b *testing.B) {
|
||||
var s structName
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
err := mapForm(&s, form)
|
||||
if err != nil {
|
||||
b.Fatalf("Error on a form mapping")
|
||||
|
||||
@ -94,7 +94,7 @@ func TestPathCleanMallocs(t *testing.T) {
|
||||
func BenchmarkPathClean(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
for _, test := range cleanTests {
|
||||
cleanPath(test.path)
|
||||
}
|
||||
@ -134,10 +134,10 @@ func TestPathCleanLong(t *testing.T) {
|
||||
|
||||
func BenchmarkPathCleanLong(b *testing.B) {
|
||||
cleanTests := genLongPaths()
|
||||
b.ResetTimer()
|
||||
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
for _, test := range cleanTests {
|
||||
cleanPath(test.path)
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ func init() {
|
||||
}
|
||||
|
||||
func BenchmarkParseAccept(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8")
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user