Monday, May 20, 2013

Check Execution Time - Stopwatch

This is a quick reference for how to check execution time in C#. This may be helpful to others but basically keeping it for my reference; as many times when needed it I need to Google it. Following code is sample I implemented in the Zipping Assembly to test which implementation is faster.

Need to reference System.Diagnostics but the implementation is quiet simple.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Archive;
using System.Diagnostics;
using System.Threading;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            ArchiveCreator ss = new WinBaseZipCreator(@"d:\testzip1.zip");
            ArchiveObj xx = ss.GetArchieve();
            xx.AddFile(@"d:\TEST1.txt");
            xx.AddFile(@"d:\TEST2.txt");
            xx.SaveArchive();
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
            Thread.Sleep(5000);
            sw.Restart();
            ArchiveCreator sss = new IonicZipCreator(@"d:\testzip2.zip");
            ArchiveObj xxx = sss.GetArchieve();
            xxx.AddFile(@"d:\TEST1.txt");
            xxx.AddFile(@"d:\TEST2.txt");
            xxx.SaveArchive();
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
            Thread.Sleep(5000);
            sw.Restart();
            ArchiveCreator ssss = new ZipShellCreator(@"d:\testzip3.zip");
            ArchiveObj xxxx = ssss.GetArchieve();
            xxxx.AddFile(@"d:\TEST1.txt");
            xxxx.AddFile(@"d:\TEST2.txt");
            xxxx.SaveArchive();
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
            Console.ReadLine();
        }
    }
}

4 comments:

  1. Your post is very helpful to quick reference to check execution time.

    ReplyDelete
  2. This article is very good. check for check it QuickShortcutMaker Clash of Clans Mod APK

    ReplyDelete
  3. If you are in Jaipur and need beautiful Escort Service in Jaipur or white skin Escort Service in Jaipur then you can simply book call girls in Jaipur from one of the best escort agency named Escort Service in Jaipur. It is No.1 premier escort agency and provide both incall or outcall facility to clients.Please click on the following link to check the official websites Escort Service in Jaipur

    ReplyDelete