Stopwatch sw=new Stopwatch();
方法
{
sw.Reset();
sw.Start();
...方法体逻辑
sw.Stop();
sw.ElapsedMilliseconds/1000;//秒级
}