The current <random> interface as defined in the standard is not well suited for heavy users such as simulations. The only way to get a number is using the operator() one-by-one. This can lead to significant overhead and, perhaps more importantly, prevents optimizations from being applied. For instance, there are way to faster implement the various distribution functions but the overhead of setting it up is too high if it has to be done for every call. Also, in some of the existing distribution implementations there are tests which the compiler cannot hoist out of the loop and therefore has to execute every time.
I propose to add a member function fill to all distribution classes. It has the same interface as the opeartor() except that it has two new parameters which specify the target buffer. This means the return value can be void, too. I know this is not standardized but I hope the standard committee will recognize it is necessary. The question is: how to add this? What is the practice to add new member functions? #ifdef something? As for the result, some distributions already show with just the current changes significant improvements. http://www.akkadia.org/drepper/fill.html The case where there seems to be a slowdown are artifacts of the micro benchmark. There is no reason that any case should be slower. I have more patches coming. We can have specialized fill functions. [ Note: not much testing can be done without modifying the header without fixing http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54376 ]
d-random-fill
Description: Binary data