Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

C# - Stopwatch class will give simple solution to calculate execution time of code

Dec 26 2011 10:49PM by Ramireddy   

Recently couple of times, I have a requirement of showing execution time to the users. Both times, I followed the approach of taking a starttime variable and stop time variable and calculating difference between those variables.

Today I saw an MSDN blog, which reminds me about the class "Stopwatch", which is specifically designed for this purpose. By using this, we can efficiently find the execution time of the code and format the result with ease.

      using System.Diagnostics;
      .......
       Stopwatch objWatch = new Stopwatch();
        objWatch.Start();
        // put your execution code here
        objWatch.Stop();
        TimeSpan ts = objWatch.Elapsed;
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Response.Write("RunTime " + elapsedTime);
Read More..   [32134 clicks]

Published under: Microsoft .NET Tips ·  ·  ·  · 


Ramireddy
2 · 40% · 12972
15
 
5
 
12
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

Your Comment


Sign Up or Login to post a comment.

"C# - Stopwatch class will give simple solution to calculate execution time of code" rated 5 out of 5 by 15 readers
C# - Stopwatch class will give simple solution to calculate execution time of code , 5.0 out of 5 based on 15 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]