jeudi 25 février 2016

Performance issue with random double generation using Mersenne twister

I have the following code:

//#include all necessary things
class RandomGenerator {
public:
   double GetRandomDbl() {
     random_device rd;
     mt19937 eng(rd());
     std::uniform_real_distribution<double> dDistribution(0,1);
     return dDistribution(eng);
     }
 };

And then I have:

int _tmain(int argc, _TCHAR* argv[])
{
RandomGenerator Rand;    //on the heap for now

for (int i = 0; i < 1000000; i++) {
double pF = Rand.GetRandomDbl();
}
}

This code alone, takes an astounding 25-28 seconds to execute on 4GB RAM. I recall reading something about instantiating a new object every time I use the Mersenne twister, but if that's the issue how should I improve this? Surely this can be made faster.




Aucun commentaire:

Enregistrer un commentaire