I have now actually benchmarked the PoissonNextSend in 3 different variants: original, round, duration_cast. Here are the results:
| ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
| 2,338.00 | 427,716.00 | 0.4% | 6,721.29 | 7,467.00 | 0.900 | 193.00 | 0.5% | 0.00 | old
| 2,380.33 | 420,109.23 | 1.8% | 6,749.57 | 7,603.17 | 0.888 | 199.29 | 0.4% | 0.00 | round
| 2,338.12 | 427,693.13 | 0.3% | 6,749.00 | 7,486.00 | 0.902 | 199.29 | 0.4% | 0.00 | duration_cast
The runtime difference here unmeasurable. The overhead is completely dwarfed by GetRand. When I then replaced GetRand with the simplest possible random generator I could think of:
inline uint64_t myRand(uint64_t maxnum) {
static uint64_t x = 1;
auto tmp = x % maxnum;
x *= 123123121;
return tmp;
}
Ran the benchmark again:
| ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
| 18.43 | 54,269,715.35 | 0.4% | 110.27 | 58.90 | 1.872 | 13.78 | 4.5% | 0.00 | original
| 24.60 | 40,642,221.28 | 0.3% | 143.80 | 78.60 | 1.830 | 20.85 | 3.1% | 0.00 | round
| 24.55 | 40,724,958.20 | 0.3% | 143.82 | 78.57 | 1.831 | 20.85 | 3.0% | 0.00 | duration_cast
There is a slight difference between duration_cast and round, but hardly significant.
So at least on my Intel CPU there is no performance argument for duration_cast in this case.