You can work out the time that an algorithm takes to run by timing it:

DimtimerAsNewStopwatch()timer.Start()Forx=1to1000000000'count to one billion!Nexttimer.Stop()' Get the elapsed time as a TimeSpan value. DimelAsTimeSpan=stopWatch.Elapsed' Format and display the TimeSpan value. DimformattedTimeAsString=String.Format("{0}:{1}:{2}.{3}",el.Hours,el.Minutes,el.Seconds,el.Milliseconds/10)Console.WriteLine("Time Elapsed: "+formattedTime)

Code Output

Time Elapsed: 0:0:21:3249

However, this isn't always suitable. What happens if you run some code on a 33MHz processor, and some code on a 3.4GHz processor. Timing a function tells you a lot about the speed of a computer and very little about the speed of an algorithm.