Android Robot

DnnForge - NewsArticles

03
When I need to know precisely how long a section of code took to execute, I create a stop watch object. I find myself using this object often during development. Hopefully it will benefit someone else also. The code below should be pretty self explanatory.

    1 using System;

    2 using System.Data;

    3 using System.Web;

    4 using System.Web.Security;

    5 using System.Web.UI;

    6 using System.Web.UI.WebControls;

    7 using System.Web.UI.HtmlControls;

    8 using System.Diagnostics;

    9 

   10 namespace WebSite

   11 {

   12   public class Class1

   13   {

   14    private static void Foobar()

   15    {

   16     Stopwatch sw;

   17     // start the stop watch

   18     sw.start();

   19 

   20     // my long running process

   21     System.Threading. Thread.Sleep(4000);

   22 

   23     // stop the stop watch

   24     sw.stop();

   25 

   26       // display the elapsed time

   27     Debug.Print(“First elapsed time {0}”,sw.ElapsedMilliseconds);

   28 

   29     //reset the stop watch

   30     sw.Reset();

   31     sw.start();

   32     System.Threading.Thread.Sleep(4000);

   33     sw.Stop();

   34 

   35     Debug.Print(“Second elapsed time {0}”,sw.ElapsedMilliseconds);

   36    }

   37   }

   38 }