C# Stopwatch to measure time

    [TestFixture]
    public class TestStopwatch
    {
        [Test]
        public void test()
        {
            //using System.Diagnostics;
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            //long running task
            int sleeptime = new Random().Next(1, 3)*1000;
            Console.WriteLine("Running for ~{0}ms:",sleeptime);
            Thread.Sleep(sleeptime);            
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed.ToString());
            Console.WriteLine(new DateTime(stopwatch.Elapsed.Ticks).ToString("ss:fff"));
        }
    }

Comments

Popular posts from this blog

Tibco Rendezvous (tibrv) C# .Net example

Parse XML to dynamic object in C#