Skip to content

Commit

Permalink
Add generator pool
Browse files Browse the repository at this point in the history
```
goos: linux
goarch: amd64
cpu: AMD Ryzen 5 3600 6-Core Processor
BenchmarkUnlimitedGoroutines-12    	       3	 407885944 ns/op	96721301 B/op	 2007116 allocs/op
BenchmarkAntsPool-12               	       2	 779131236 ns/op	20097156 B/op	 1064950 allocs/op
BenchmarkGammaZeroPool-12          	       1	1162897642 ns/op	19343432 B/op	 1057008 allocs/op
BenchmarkItogamiPool-12            	       3	 431012905 ns/op	28744213 B/op	 1051633 allocs/op
BenchmarkGenerator-12              	       5	 230959863 ns/op	 4823598 B/op	  100013 allocs/op
```

It is far faster than other alternatives.
  • Loading branch information
Jorropo committed Jun 16, 2022
1 parent 8990817 commit 13f8205
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
17 changes: 17 additions & 0 deletions general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package test

import (
"sync"
"sync/atomic"
"testing"
"time"

"github.com/Jorropo/generator"
"github.com/alphadose/itogami"
"github.com/gammazero/workerpool"
"github.com/panjf2000/ants/v2"
Expand Down Expand Up @@ -89,3 +91,18 @@ func BenchmarkItogamiPool(b *testing.B) {
}
b.StopTimer()
}

func BenchmarkGenerator(b *testing.B) {
for i := b.N; i != 0; i-- {
var count uint64 = 1<<64 - 1 // start at -1 since atomic.AddUint64
p := generator.NewPool(func() (generator.Runner, bool) {
i := atomic.AddUint64(&count, 1)
if i < RunTimes {
return demoFunc, true
}
return nil, false
}, PoolSize)

p.Wait()
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/alphadose/go-threadpool-benchmarks
go 1.18

require (
github.com/Jorropo/generator v0.0.0-20220616120754-5d6e46dcc82c // indirect
github.com/alphadose/itogami v0.0.0-20220615140746-2256de286af9 // indirect
github.com/gammazero/deque v0.1.0 // indirect
github.com/gammazero/workerpool v1.1.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Jorropo/generator v0.0.0-20220616120754-5d6e46dcc82c h1:hSg0QTZE20zlP6SGtAHbVFsRLPB1YsvC+pGAQvbVU1Q=
github.com/Jorropo/generator v0.0.0-20220616120754-5d6e46dcc82c/go.mod h1:7SJu0EPhAyeVonijsVuOFpMO0gV8fa52FXe+CT36Epo=
github.com/alphadose/itogami v0.0.0-20220615140746-2256de286af9 h1:JxYFFzuDpkqFHm2Fxtz0v+f3YEPTNiRPtWLxVHSRxuc=
github.com/alphadose/itogami v0.0.0-20220615140746-2256de286af9/go.mod h1:QDsatlDSUJB4sXxZsJEpawGnTDwSdvX27ZXqtuZY3WA=
github.com/gammazero/deque v0.1.0 h1:f9LnNmq66VDeuAlSAapemq/U7hJ2jpIWa4c09q8Dlik=
Expand Down
19 changes: 19 additions & 0 deletions vendor/github.com/Jorropo/generator/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions vendor/github.com/Jorropo/generator/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# github.com/Jorropo/generator v0.0.0-20220616120754-5d6e46dcc82c
## explicit; go 1.18
github.com/Jorropo/generator
# github.com/alphadose/itogami v0.0.0-20220615140746-2256de286af9
## explicit; go 1.18
github.com/alphadose/itogami
Expand Down

0 comments on commit 13f8205

Please sign in to comment.