Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time spend running program

How I print in a textbox or at the output the time that the program spend running?

I want it to be displayed into a for-loop, to get how much time each for-loop needs.

like image 434
george mano Avatar asked Oct 20 '11 13:10

george mano


1 Answers

You could try:

DateTime dt = DateTime.Now;
for (.......)
{
}
TimeSpan ts = DateTime.Now - dt;
textbox1.Text = ts.TotalMilliseconds.ToString();

or (according to MSDN) if you need better resolution

Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
for (.......)
{
}
stopWatch.Stop();
textbox1.Text = stopWatch.ElapsedMilliseconds.ToString();
like image 79
Marco Avatar answered Nov 02 '22 13:11

Marco