Константин Иванов
unread,Nov 26, 2024, 12:14:51 PM (7 days ago) Nov 26Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Hello.
Is there a way to determine current parallelism inside a BenchmarkXX function?
The problem.
I need to run some tests using P connections with P parallelism.
Using `-cpu=1,2,4,etc` flag I can set the P. But can't get it inside
my benchmark funciton.
Using
`b.SetParallelism(P)` I can only set `P*GOMAXPROCS`. Seems, I need
`-cpu=1` and then `b.SetParallelism(P)` to achieve the target.
Is there another way? The `-cpu=1,2,4` looks good. But I can't prepare before tests, because I don't know the P.
My benchmark (in short)
```go
func Benchamark(b *testing.B) {
// 1. create P connections
var conns = create(P)
b.ResetTimer()
b.SetParallelism(P)
b.RunParallel(/* use the conns */)
}
```
Regards.