I am trying to write high performance code that uses random numbers, using Mersenne Twister. It takes roughly ~5ns to generate a random unsigned long long. This is used to generate a double, however these take ~40ns to generate in a distribution.
Viewing the STL code the doubles, generated by a distribution, a generated by calls to std::generate_canonical, which involves a std::ceil and std::log2 operation, I believe it is these that are costly.
These operations are unnecessary as they are used to calculate the number of bits needed for calls to any RNG implementation. As this is known before compile time, I have written my own implementation that does not make these calls, and the time to generate a double is ~15ns.
Is it possible to specialise a templated STL function? If so how is this achieved, my attempts so far result in the original function still being used. I would like to specialise this STL function as I would still like to use the distributions in .
This is in Visual C++, though once code has been developed it will be run on Linux. If the method for generating doubles on Linux is different, (and quicker), this problem is irrelevant.
Aucun commentaire:
Enregistrer un commentaire