-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
119 lines (98 loc) · 2.43 KB
/
benchmark_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
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
118
119
package sworker
import (
"context"
"fmt"
"runtime"
"testing"
"github.com/mayur-tolexo/sworker/draught"
)
func print(ctx context.Context, value ...interface{}) (err error) {
return nil
}
func BenchmarkSworker(b *testing.B) {
for i := 1; i <= runtime.NumCPU()+1; i++ {
// i := runtime.NumCPU()
b.Run(fmt.Sprintf("%v-Worker", i), func(b *testing.B) {
runDraughtBenchmark(b, i)
})
}
}
func runDraughtBenchmark(b *testing.B, wCount int) {
handler := print
pool := draught.NewPool(b.N, "", nil)
pool.AddWorker(wCount, handler, true)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
pool.AddJob(1)
}
})
pool.Close()
}
// func executeServe(p *slaves.Pool, rounds int) {
// for i := 0; i < rounds; i++ {
// p.Serve(i)
// }
// }
// func BenchmarkSlavePool(b *testing.B) {
// ch := make(chan int, b.N)
// sp := slaves.NewPool(0, func(obj interface{}) {
// ch <- obj.(int)
// })
// go executeServe(&sp, b.N)
// i := 0
// for i < b.N {
// select {
// case <-ch:
// i++
// }
// }
// close(ch)
// sp.Close()
// }
// func BenchmarkGrPool(b *testing.B) {
// n := runtime.NumCPU()
// b.Run(fmt.Sprintf("%v-Worker", n), func(b *testing.B) {
// // number of workers, and size of job queue
// pool := grpool.NewPool(n, b.N)
// defer pool.Release()
// // how many jobs we should wait
// pool.WaitCount(b.N)
// // submit one or more jobs to pool
// for i := 0; i < b.N; i++ {
// pool.JobQueue <- func() {
// // say that job is done, so we can know how many jobs are finished
// defer pool.JobDone()
// }
// }
// // wait until we call JobDone for all jobs
// pool.WaitAll()
// })
// }
// func BenchmarkTunny(b *testing.B) {
// pool := tunny.NewFunc(10, func(in interface{}) interface{} {
// intVal := in.(int)
// return intVal * 2
// })
// defer pool.Close()
// b.ResetTimer()
// for i := 0; i < b.N; i++ {
// ret := pool.Process(10)
// if exp, act := 20, ret.(int); exp != act {
// b.Errorf("Wrong result: %v != %v", act, exp)
// }
// }
// }
// func BenchmarkWorkerpool(b *testing.B) {
// n := runtime.NumCPU()
// b.Run(fmt.Sprintf("%v-Worker", n), func(b *testing.B) {
// wp := workerpool.New(n)
// defer wp.Stop()
// releaseChan := make(chan struct{})
// b.ResetTimer()
// // Start workers, and have them all wait on a channel before completing.
// for i := 0; i < b.N; i++ {
// wp.Submit(func() { <-releaseChan })
// }
// close(releaseChan)
// })
// }