System.Diagnostics.Stopwatch watch = new Stopwatch();watch.Start();
//要计算的操作
DoSomeThing();
watch.Stop();TimeSpan timeSpan = watch.Elapsed;