Skip to content

Commit 1429c70

Browse files
committed
refactor(tests): use b.Loop()
1 parent 9a4d135 commit 1429c70

File tree

11 files changed

+458
-458
lines changed

11 files changed

+458
-458
lines changed

models/auth/oauth2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
2525
func BenchmarkOAuth2Application_GenerateClientSecret(b *testing.B) {
2626
assert.NoError(b, unittest.PrepareTestDatabase())
2727
app := unittest.AssertExistsAndLoadBean(b, &auth_model.OAuth2Application{ID: 1})
28-
for i := 0; i < b.N; i++ {
28+
for b.Loop() {
2929
_, _ = app.GenerateClientSecret(db.DefaultContext)
3030
}
3131
}

models/unittest/fixtures_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ func BenchmarkFixturesLoader(b *testing.B) {
9999
// BenchmarkFixturesLoader/Internal
100100
// BenchmarkFixturesLoader/Internal-12 1746 670457 ns/op
101101
b.Run("Internal", func(b *testing.B) {
102-
for i := 0; i < b.N; i++ {
102+
for b.Loop() {
103103
require.NoError(b, loaderInternal.Load())
104104
}
105105
})
106106
b.Run("Vendor", func(b *testing.B) {
107107
if loaderVendor == nil {
108108
b.Skip()
109109
}
110-
for i := 0; i < b.N; i++ {
110+
for b.Loop() {
111111
require.NoError(b, loaderVendor.Load())
112112
}
113113
})

models/user/user_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func BenchmarkHashPassword(b *testing.B) {
200200
pass := "password1337"
201201
u := &user_model.User{Passwd: pass}
202202
b.ResetTimer()
203-
for i := 0; i < b.N; i++ {
203+
for b.Loop() {
204204
u.SetPassword(pass)
205205
}
206206
}

modules/git/blob_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func Benchmark_Blob_Data(b *testing.B) {
4747
b.Fatal(err)
4848
}
4949

50-
for i := 0; i < b.N; i++ {
50+
for b.Loop() {
5151
r, err := testBlob.DataAsync()
5252
if err != nil {
5353
b.Fatal(err)

modules/git/commit_info_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
158158
entries.Sort()
159159
b.ResetTimer()
160160
b.Run(benchmark.name, func(b *testing.B) {
161-
for i := 0; i < b.N; i++ {
161+
for b.Loop() {
162162
_, _, err := entries.GetCommitsInfo(b.Context(), commit, "")
163163
if err != nil {
164164
b.Fatal(err)

modules/git/repo_branch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func BenchmarkRepository_GetBranches(b *testing.B) {
4747
}
4848
defer bareRepo1.Close()
4949

50-
for i := 0; i < b.N; i++ {
50+
for b.Loop() {
5151
_, _, err := bareRepo1.GetBranchNames(0, 0)
5252
if err != nil {
5353
b.Fatal(err)

modules/markup/html_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) {
522522
data += data
523523
}
524524
b.ResetTimer()
525-
for i := 0; i < b.N; i++ {
525+
for b.Loop() {
526526
var res strings.Builder
527527
err := markup.PostProcessDefault(markup.NewTestRenderContext(localMetas), strings.NewReader(data), &res)
528528
assert.NoError(b, err)

modules/markup/markdown/markdown_benchmark_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212

1313
func BenchmarkSpecializedMarkdown(b *testing.B) {
1414
// 240856 4719 ns/op
15-
for i := 0; i < b.N; i++ {
15+
for b.Loop() {
1616
markdown.SpecializedMarkdown(&markup.RenderContext{})
1717
}
1818
}
1919

2020
func BenchmarkMarkdownRender(b *testing.B) {
2121
// 23202 50840 ns/op
22-
for i := 0; i < b.N; i++ {
22+
for b.Loop() {
2323
_, _ = markdown.RenderString(markup.NewTestRenderContext(), "https://example.com\n- a\n- b\n")
2424
}
2525
}

modules/util/runtime_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ func TestCallerFuncName(t *testing.T) {
1818
func BenchmarkCallerFuncName(b *testing.B) {
1919
// BenchmarkCaller/sprintf-12 12744829 95.49 ns/op
2020
b.Run("sprintf", func(b *testing.B) {
21-
for i := 0; i < b.N; i++ {
21+
for b.Loop() {
2222
_ = fmt.Sprintf("aaaaaaaaaaaaaaaa %s %s %s", "bbbbbbbbbbbbbbbbbbb", b.Name(), "ccccccccccccccccccccc")
2323
}
2424
})
2525
// BenchmarkCaller/caller-12 10625133 113.6 ns/op
2626
// It is almost as fast as fmt.Sprintf
2727
b.Run("caller", func(b *testing.B) {
28-
for i := 0; i < b.N; i++ {
28+
for b.Loop() {
2929
CallerFuncName(1)
3030
}
3131
})

modules/util/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func TestToUpperASCII(t *testing.T) {
215215
func BenchmarkToUpper(b *testing.B) {
216216
for _, tc := range upperTests {
217217
b.Run(tc.in, func(b *testing.B) {
218-
for i := 0; i < b.N; i++ {
218+
for b.Loop() {
219219
ToUpperASCII(tc.in)
220220
}
221221
})

0 commit comments

Comments
 (0)