加入了shell就方便使用了! 这样用就很爽了!
//方便的进行 性能测试,再也不用定义时间减去时间了!
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 1; i < 1000000; i++) { } // Execute the task to be timed
watch.Stop();
Console.WriteLine("Elapsed: {0}",watch.Elapsed);
Console.WriteLine("In milliseconds: {0}",watch.ElapsedMilliseconds);
Console.WriteLine("In timer ticks: {0}",watch.ElapsedTicks);
用个action包裹就把很多事情节省了!
public static void TimeOf_Shell(Action xn = null)
{
Stopwatch watch = new Stopwatch();
watch.Start();
if (xn.NotNull())
{
xn();
}
watch.Stop();
Console.WriteLine("Elapsed: {0}", watch.Elapsed);
Console.WriteLine("In milliseconds: {0}", watch.ElapsedMilliseconds);
Console.WriteLine("In timer ticks: {0}", watch.ElapsedTicks);
}
具体用法
TimeOf_Shell(() =>
{
var f_md52 = HashHelper.ComputeMD5(f_name);
WriteLine(f_md52);
});