-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
44 lines (32 loc) · 687 Bytes
/
Copy pathbenchmark_test.go
File metadata and controls
44 lines (32 loc) · 687 Bytes
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
package gollback
import (
"context"
"errors"
"testing"
)
func BenchmarkRace(b *testing.B) {
cbs := getCallbacks(b)
b.ResetTimer()
Race(context.Background(), cbs...)
}
func BenchmarkAll(b *testing.B) {
cbs := getCallbacks(b)
b.ResetTimer()
All(context.Background(), cbs...)
}
func BenchmarkRetry(b *testing.B) {
err := errors.New("failed")
b.ResetTimer()
Retry(context.Background(), b.N, func(ctx context.Context) (interface{}, error) {
return nil, err
})
}
func getCallbacks(b *testing.B) []AsyncFunc {
cbs := make([]AsyncFunc, b.N)
for n := 0; n < b.N; n++ {
cbs[n] = func(ctx context.Context) (interface{}, error) {
return n, nil
}
}
return cbs
}