c# 测试方法执行时间
class Program { static void Main(string[] args) { Console.WriteLine(ActionExtension.Profiler(a, 10)); } static void a() { } } //public class test : ICorProfilerCallback //{ //} public static class ActionExtension { public static string Profiler(this Action func, int runcount) { Stopwatch watch = Stopwatch.StartNew();//创建一个监听器 for (int i = 0; i < runcount; i++) { func();//执行某个方法 } watch.Stop(); float sec = watch.ElapsedMilliseconds / 1000.0f; float freq = sec / runcount; return string.Format("总体执行时间为:{0}秒,总体执行次数为:{1},平均执行时间为:{2}秒", sec, runcount, freq); } }
以沫浅夏----奔跑的孩子
个人博客地址:http://www.blog.liyang.love
个人博客地址:http://www.blog.liyang.love