Random.NextBytes Performance Issues

יום שלישי, מרץ 4, 2008

 בעיות ביצועים עם מחלקת Random I have became aware recently to a performance problem with the Random class, specifically the Random.NextBytes method.As it turns out this is an expansive operation:The graph displays the number of milliseconds used to perform 10,000,000 operations.The NextBytes method handle a byte array containing only 4 bytes.This is linear - using an array of 4000 bytes will take 1000 times longer to complete the operation!However, there may be a work-around using the BitConverter class.Use BitConverter.GetBytes(Random.NextDouble()) to get a randomized array of 8 bytes.Here are the results: