Skip to content

Commit 83a49b5

Browse files
committed
test: add benchmarks.
1 parent 7c7871b commit 83a49b5

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

all_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ func TestAllWithTimeoutContext(t *testing.T) {
9797
a.EqualNow(data, []bool{true, true, false, false, false})
9898
}
9999

100+
func BenchmarkAll(b *testing.B) {
101+
tasks := make([]AsyncFn, 0, 1000)
102+
for i := 0; i < 1000; i++ {
103+
tasks = append(tasks, func(ctx context.Context) error {
104+
return nil
105+
})
106+
}
107+
108+
All(tasks...)
109+
}
110+
100111
func TestAllCompletedWithoutFuncs(t *testing.T) {
101112
a := assert.New(t)
102113

@@ -191,3 +202,14 @@ func TestAllCompletedWithTimeoutContext(t *testing.T) {
191202
a.EqualNow(data, []bool{true, true, false, false, false})
192203
a.EqualNow(errs, []error{nil, nil, errTimeout, errTimeout, errTimeout})
193204
}
205+
206+
func BenchmarkAllCompleted(b *testing.B) {
207+
tasks := make([]AsyncFn, 0, 1000)
208+
for i := 0; i < 1000; i++ {
209+
tasks = append(tasks, func(ctx context.Context) error {
210+
return nil
211+
})
212+
}
213+
214+
AllCompleted(tasks...)
215+
}

parallel_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ func TestParallelWithTimedOutContext(t *testing.T) {
138138
a.EqualNow(finishedNum, 2)
139139
}
140140

141+
func BenchmarkParallel(b *testing.B) {
142+
tasks := make([]AsyncFn, 0, 1000)
143+
for i := 0; i < 1000; i++ {
144+
tasks = append(tasks, func(ctx context.Context) error {
145+
return nil
146+
})
147+
}
148+
149+
Parallel(5, tasks...)
150+
}
151+
141152
func TestParallelCompleted(t *testing.T) {
142153
a := assert.New(t)
143154

@@ -283,3 +294,14 @@ func TestParallelCompletedWithTimedOutContext(t *testing.T) {
283294
}
284295
a.EqualNow(finishedNum, 2)
285296
}
297+
298+
func BenchmarkParallelCompleted(b *testing.B) {
299+
tasks := make([]AsyncFn, 0, 1000)
300+
for i := 0; i < 1000; i++ {
301+
tasks = append(tasks, func(ctx context.Context) error {
302+
return nil
303+
})
304+
}
305+
306+
ParallelCompleted(5, tasks...)
307+
}

race_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,14 @@ func TestRaceWithContext(t *testing.T) {
8282
time.Sleep(300 * time.Millisecond)
8383
a.EqualNow(data, []bool{true, true, true, false, false})
8484
}
85+
86+
func BenchmarkRace(b *testing.B) {
87+
tasks := make([]AsyncFn, 0, 1000)
88+
for i := 0; i < 1000; i++ {
89+
tasks = append(tasks, func(ctx context.Context) error {
90+
return nil
91+
})
92+
}
93+
94+
Race(tasks...)
95+
}

0 commit comments

Comments
 (0)