首页 > Windows开发 > 详细

c# 测试方法执行时间

时间:2017-11-28 13:04:18      阅读:226      评论:0      收藏:0      [点我收藏+]
    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);
        }
    }

 

c# 测试方法执行时间

原文:http://www.cnblogs.com/liyangLife/p/7909233.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!