> >using System; >using System.Text; > >namespace SpeedTest >{ > using System.Diagnostics; > > public class Program > { > public static void Main() > { > SpeedTest(); > > Console.Write("\n\nAny key..."); > Console.ReadKey(); > } > > private static void SpeedTest() > { > const int MaxIndex = 1000000; > > var stopwatch = new Stopwatch(); > stopwatch.Start(); > > for (var index = 0; index < MaxIndex; index++) > { > var var1 = Math.Log(index) + > Math.Cos(index) + > Math.Sin(index) + > Math.Log(index) + > Math.Exp(index); > } > > stopwatch.Stop(); > Console.WriteLine("Test 01: {0}", stopwatch.Elapsed); > > // AM using string type in .NET for this type of test > // would be unreasonable. StringBuilder Class is used instead. > var stringBuilder = new StringBuilder(); > > stopwatch.Reset(); > stopwatch.Start(); > > for (var index = 0; index < MaxIndex; index++) > { > stringBuilder.Append("xx"); > } > > string result = stringBuilder.ToString(); > > stopwatch.Stop(); > Console.WriteLine("Test 02: {0}", stopwatch.Elapsed); > } > } >} >