c# 测试方法执行时间
2021-04-26 00:27
标签:top count int art cti 次数 void write line c# 测试方法执行时间 标签:top count int art cti 次数 void write line 原文地址:http://www.cnblogs.com/liyangLife/p/7909233.html 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 )
{
func();//执行某个方法
}
watch.Stop();
float sec = watch.ElapsedMilliseconds / 1000.0f;
float freq = sec / runcount;
return string.Format("总体执行时间为:{0}秒,总体执行次数为:{1},平均执行时间为:{2}秒", sec, runcount, freq);
}
}