mirror of
https://github.com/gin-gonic/gin.git
synced 2025-12-06 23:57:07 +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.ReportAllocs()
|
||||||
b.ResetTimer()
|
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
if len(e.Error()) == 0 {
|
if len(e.Error()) == 0 {
|
||||||
b.Errorf("error")
|
b.Errorf("error")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ type structFull struct {
|
|||||||
|
|
||||||
func BenchmarkMapFormFull(b *testing.B) {
|
func BenchmarkMapFormFull(b *testing.B) {
|
||||||
var s structFull
|
var s structFull
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
err := mapForm(&s, form)
|
err := mapForm(&s, form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("Error on a form mapping")
|
b.Fatalf("Error on a form mapping")
|
||||||
@ -54,7 +54,7 @@ type structName struct {
|
|||||||
|
|
||||||
func BenchmarkMapFormName(b *testing.B) {
|
func BenchmarkMapFormName(b *testing.B) {
|
||||||
var s structName
|
var s structName
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
err := mapForm(&s, form)
|
err := mapForm(&s, form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("Error on a form mapping")
|
b.Fatalf("Error on a form mapping")
|
||||||
|
|||||||
@ -94,7 +94,7 @@ func TestPathCleanMallocs(t *testing.T) {
|
|||||||
func BenchmarkPathClean(b *testing.B) {
|
func BenchmarkPathClean(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
for _, test := range cleanTests {
|
for _, test := range cleanTests {
|
||||||
cleanPath(test.path)
|
cleanPath(test.path)
|
||||||
}
|
}
|
||||||
@ -134,10 +134,10 @@ func TestPathCleanLong(t *testing.T) {
|
|||||||
|
|
||||||
func BenchmarkPathCleanLong(b *testing.B) {
|
func BenchmarkPathCleanLong(b *testing.B) {
|
||||||
cleanTests := genLongPaths()
|
cleanTests := genLongPaths()
|
||||||
b.ResetTimer()
|
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
for _, test := range cleanTests {
|
for _, test := range cleanTests {
|
||||||
cleanPath(test.path)
|
cleanPath(test.path)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkParseAccept(b *testing.B) {
|
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")
|
parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user