开发者

Is there some library to help writing instrumentation like measuring the execution time of the methods

开发者 https://www.devze.com 2023-02-23 09:32 出处:网络
Any library which can assist those tasks?开发者_运维技巧 You can use the Stopwatch class using System;

Any library which can assist those tasks?开发者_运维技巧


You can use the Stopwatch class

using System;
using System.Diagnostics;
using System.Threading;
class Program
{
  static void Main(string[] args)
   {
    Stopwatch stopWatch = new Stopwatch();
    stopWatch.Start();
    Thread.Sleep(10000);
    stopWatch.Stop();
    // Get the elapsed time as a TimeSpan value.
    TimeSpan ts = stopWatch.Elapsed;

    // Format and display the TimeSpan value.
    string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
        ts.Hours, ts.Minutes, ts.Seconds,
        ts.Milliseconds / 10);
    Console.WriteLine("RunTime " + elapsedTime);
}

}

MSDN


PostSharp - Performace Counters


Visual Studio has a profiler - I think it is available only in the Pro edition and above. IT works nicely in general.

If you have more specific or particular needs you may want to look into PostSharp or other add-ons.

0

精彩评论

暂无评论...
验证码 换一张
取 消