-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathbloop_test.go
More file actions
117 lines (98 loc) · 1.93 KB
/
bloop_test.go
File metadata and controls
117 lines (98 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//go:build go1.25
//golangcitest:args -Emodernize
//golangcitest:expected_exitcode 0
package bloop
import (
"sync"
"testing"
)
func BenchmarkA(b *testing.B) {
println("slow")
b.ResetTimer()
for range b.N { // want "b.N can be modernized using b.Loop.."
}
}
func BenchmarkB(b *testing.B) {
// setup
{
b.StopTimer()
println("slow")
b.StartTimer()
}
for i := range b.N { // Nope. Should we change this to "for i := 0; b.Loop(); i++"?
print(i)
}
b.StopTimer()
println("slow")
}
func BenchmarkC(b *testing.B) {
// setup
{
b.StopTimer()
println("slow")
b.StartTimer()
}
for i := 0; i < b.N; i++ { // want "b.N can be modernized using b.Loop.."
println("no uses of i")
}
b.StopTimer()
println("slow")
}
func BenchmarkD(b *testing.B) {
for i := 0; i < b.N; i++ { // want "b.N can be modernized using b.Loop.."
println(i)
}
}
func BenchmarkE(b *testing.B) {
b.Run("sub", func(b *testing.B) {
b.StopTimer() // not deleted
println("slow")
b.StartTimer() // not deleted
// ...
})
b.ResetTimer()
for i := 0; i < b.N; i++ { // want "b.N can be modernized using b.Loop.."
println("no uses of i")
}
b.StopTimer()
println("slow")
}
func BenchmarkF(b *testing.B) {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < b.N; i++ { // nope: b.N accessed from a FuncLit
}
}()
wg.Wait()
}
func BenchmarkG(b *testing.B) {
var wg sync.WaitGroup
poster := func() {
for i := 0; i < b.N; i++ { // nope: b.N accessed from a FuncLit
}
wg.Done()
}
wg.Add(2)
for i := 0; i < 2; i++ {
go poster()
}
wg.Wait()
}
func BenchmarkH(b *testing.B) {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
for range b.N { // nope: b.N accessed from a FuncLit
}
}()
wg.Wait()
}
func BenchmarkI(b *testing.B) {
for i := 0; i < b.N; i++ { // nope: b.N accessed more than once in benchmark
}
for i := 0; i < b.N; i++ { // nope: b.N accessed more than once in benchmark
}
}