Get a benchmark parallelism inside the benchmark?

59 views
Skip to first unread message

Константин Иванов

unread,
Nov 26, 2024, 12:14:51 PM (7 days ago) Nov 26
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.
Reply all
Reply to author
Forward
0 new messages