mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-30 22:48:39 +08:00
fix: for loop can be modernized using range over int
This commit is contained in:
commit
a7d6241989
@ -154,7 +154,7 @@ func runRequest(B *testing.B, r *Engine, method, path string) {
|
||||
w := newMockWriter()
|
||||
B.ReportAllocs()
|
||||
B.ResetTimer()
|
||||
for range B.N {
|
||||
for B.Loop() {
|
||||
r.ServeHTTP(w, req)
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ func BenchmarkSliceValidationError(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for range b.N {
|
||||
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 range b.N {
|
||||
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 range b.N {
|
||||
for b.Loop() {
|
||||
err := mapForm(&s, form)
|
||||
if err != nil {
|
||||
b.Fatalf("Error on a form mapping")
|
||||
|
||||
@ -3632,7 +3632,7 @@ func BenchmarkGetMapFromFormData(b *testing.B) {
|
||||
for _, bm := range benchmarks {
|
||||
b.Run(bm.name, func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for range b.N {
|
||||
for b.Loop() {
|
||||
_, _ = getMapFromFormData(bm.data, bm.key)
|
||||
}
|
||||
})
|
||||
|
||||
@ -81,25 +81,25 @@ func TestStringToBytes(t *testing.T) {
|
||||
// go test -v -run=none -bench=^BenchmarkBytesConv -benchmem=true
|
||||
|
||||
func BenchmarkBytesConvBytesToStrRaw(b *testing.B) {
|
||||
for range b.N {
|
||||
for b.Loop() {
|
||||
rawBytesToStr(testBytes)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBytesConvBytesToStr(b *testing.B) {
|
||||
for range b.N {
|
||||
for b.Loop() {
|
||||
BytesToString(testBytes)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBytesConvStrToBytesRaw(b *testing.B) {
|
||||
for range b.N {
|
||||
for b.Loop() {
|
||||
rawStrToBytes(testString)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBytesConvStrToBytes(b *testing.B) {
|
||||
for range b.N {
|
||||
for b.Loop() {
|
||||
StringToBytes(testString)
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ func TestPathCleanMallocs(t *testing.T) {
|
||||
func BenchmarkPathClean(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
for range b.N {
|
||||
for {
|
||||
for _, test := range cleanTests {
|
||||
cleanPath(test.path)
|
||||
}
|
||||
@ -137,7 +137,7 @@ func BenchmarkPathCleanLong(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for range b.N {
|
||||
for b.Loop() {
|
||||
for _, test := range cleanTests {
|
||||
cleanPath(test.path)
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ func init() {
|
||||
}
|
||||
|
||||
func BenchmarkParseAccept(b *testing.B) {
|
||||
for range b.N {
|
||||
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