
"Jos Hickson" <jos.hickson@gmail.com> wrote in news:fc03d05a0706010913l4865ef29re605685969592243@mail.gmail.com:
On 01/06/07, Dave Jenkins <david@jenkins.net> wrote:
Andy, You did a nice job speeding up the uuid::create(engine) function to 0.4 seconds for 1 million UUIDs. But now the uuid::create() function is extremely slow - 131 seconds for 1 million UUIDs (source code below). Can you change it to use a static mt19937 engine?
There was opposition to using static objects because of threading concerns. I do want a function that doesn't require the user to create a random number generator themselves. If I use a static engine, I need to protect it with a mutex. This is not optimal because there is the overhead of locking and unlocking the mutex. Some people would rather have a static engine per thread using thread local storage. This still requires one to link with Boost.Thread. I created the uuid::create(Engine) function (great advice from this list) so that users could do whatever they want (static engine per thread, use thread local storage,...). The uuid::create() function should handle the common case and not be best for all situations. So, I guess I need help to determine what the common case is.
On a related note: doesn't reseeding the random number generator every time uuid::create() is called reduce the quality of the random numbers from the mt19937 engine?
Probably.
Doesn't the randomness then come from the seeding mechanism which is used? So, on the whole it would indeed be better to use a static engine if possible.
Regards,
Jos
Andy.