using System; using System.Diagnostics; public class Test { static Random random = new Random(); public static Double Random() { return random.NextDouble(); } public static Double Random2() { return -1; } public static void Main() { { Stopwatch s = new Stopwatch(); Double a = 0; s.Start(); for (Int32 i = 0; i < 5000000; i++) a += Random(); s.Stop(); Console.WriteLine(s.ElapsedMilliseconds); } { Stopwatch s = new Stopwatch(); Double a = 0; s.Start(); for (Int32 i = 0; i < 5000000; i++) a += Random2(); s.Stop(); Console.WriteLine(s.ElapsedMilliseconds); } { Stopwatch s = new Stopwatch(); Double a = 0; s.Start(); for (Int32 i = 0; i < 5000000; i++) a += random.NextDouble(); s.Stop(); Console.WriteLine(s.ElapsedMilliseconds); } } }