Skip to content

Commit 72ce568

Browse files
committed
Added a benchmark function
1 parent 273bd3f commit 72ce568

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

grpool_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package grpool
22

33
import (
4+
"io/ioutil"
5+
"log"
46
"runtime"
57
"sync/atomic"
68
"testing"
@@ -84,3 +86,18 @@ func TestRelease(t *testing.T) {
8486

8587
pool.WaitAll()
8688
}
89+
90+
func BenchmarkPool(b *testing.B) {
91+
// Testing with just 1 goroutine
92+
// to benchmark the non-parallel part of the code
93+
pool := NewPool(1, 10)
94+
defer pool.Release()
95+
96+
log.SetOutput(ioutil.Discard)
97+
98+
for n := 0; n < b.N; n++ {
99+
pool.JobQueue <- func() {
100+
log.Printf("I am worker! Number %d\n", n)
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)