-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench_test.go
63 lines (51 loc) · 1.32 KB
/
bench_test.go
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
package gopool
import (
"context"
"sync"
"testing"
"time"
)
func BenchmarkGoPool_Schedule(b *testing.B) {
ctx := context.Background()
pool, err := New(ctx, 500, 500, 500, time.Second)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
var wg sync.WaitGroup
j := fakeTask{doF: func() {
wg.Done()
}}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg.Add(1)
_ = pool.Schedule(j)
}
wg.Wait()
close(pool.shutdown)
}
func BenchmarkGoPool_Schedule_ColdStart(b *testing.B) {
ctx := context.Background()
pool, err := New(ctx, 500, 500, 1, time.Second)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
var wg sync.WaitGroup
j := fakeTask{doF: func() {
wg.Done()
}}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg.Add(1)
_ = pool.Schedule(j)
}
wg.Wait()
close(pool.shutdown)
}
// go 1.11.13
//BenchmarkGoPool_Schedule-8 10000 206643 ns/op 7 B/op 0 allocs/op
//BenchmarkGoPool_Schedule_ColdStart-8 10000 207100 ns/op 15 B/op 0 allocs/op
// go 1.13.4
//BenchmarkGoPool_Schedule-8 4696 220266 ns/op 15 B/op 0 allocs/op
//BenchmarkGoPool_Schedule_ColdStart-8 4892 211635 ns/op 33 B/op 0 allocs/op