@@ -156,12 +156,12 @@ func BenchmarkIsContextType(b *testing.B) {
156156 b .Run ("value" , func (b * testing.B ) {
157157 ctx := context .Background ()
158158 ctxs := make ([]reflect.Type , b .N )
159- for i := 0 ; i < b . N ; i ++ {
159+ for i := 0 ; b . Loop () ; i ++ {
160160 ctxs [i ] = reflect .TypeOf (context .WithValue (ctx , k ("key" ), i ))
161161 }
162162
163163 b .ResetTimer ()
164- for i := 0 ; i < b . N ; i ++ {
164+ for i := 0 ; b . Loop () ; i ++ {
165165 if ! IsContextType (ctxs [i ]) {
166166 b .Fatal ("not context" )
167167 }
@@ -170,7 +170,7 @@ func BenchmarkIsContextType(b *testing.B) {
170170
171171 b .Run ("background" , func (b * testing.B ) {
172172 var ctxt reflect.Type = reflect .TypeOf (context .Background ())
173- for i := 0 ; i < b . N ; i ++ {
173+ for b . Loop () {
174174 if ! IsContextType (ctxt ) {
175175 b .Fatal ("not context" )
176176 }
@@ -189,8 +189,7 @@ func BenchmarkIsTruthFulValue(b *testing.B) {
189189 nilPointer = reflect .ValueOf ((* zeroStruct )(nil ))
190190 )
191191
192- b .ResetTimer ()
193- for i := 0 ; i < b .N ; i ++ {
192+ for b .Loop () {
194193 IsTruthfulValue (stringHugo )
195194 IsTruthfulValue (stringEmpty )
196195 IsTruthfulValue (zero )
@@ -227,8 +226,7 @@ func BenchmarkGetMethodByNameForType(b *testing.B) {
227226 tp := reflect .TypeFor [* testStruct ]()
228227 methods := []string {"Method1" , "Method2" , "Method3" , "Method4" , "Method5" }
229228
230- b .ResetTimer ()
231- for i := 0 ; i < b .N ; i ++ {
229+ for b .Loop () {
232230 for _ , method := range methods {
233231 _ = GetMethodByNameForType (tp , method )
234232 }
@@ -239,8 +237,7 @@ func BenchmarkGetMethodByName(b *testing.B) {
239237 v := reflect .ValueOf (& testStruct {})
240238 methods := []string {"Method1" , "Method2" , "Method3" , "Method4" , "Method5" }
241239
242- b .ResetTimer ()
243- for i := 0 ; i < b .N ; i ++ {
240+ for b .Loop () {
244241 for _ , method := range methods {
245242 _ = GetMethodByName (v , method )
246243 }
0 commit comments