samedi 16 novembre 2019

performance issue with std::normal_distribution?

One of the classes I use has a data member that is a std::vector of about 12 million numbers (float or double). If I just read it from file and write it, that takes much less than a second. But if I also add normally distributed noise using this function

void addNormalNoise ( double mu, double sigma ) {

std::random_device    randomdevice {};
std::mt19937 engine { randomdevice ()  };

std::normal_distribution <double> normaldist ( mu, sigma );
for ( size_t i = 0; i < data.size(); i++ )
      data[i] += normaldist ( engine );

}

it takes almost 3 seconds to run. To me this is the simplest and most direct way of calling the normaldist function, but is this hopelessly inefficient in some way? What is causing the delay?




Aucun commentaire:

Enregistrer un commentaire