c计时器
用法1:
#include "time.h"
clock_t start, finish;
start = clock();
... ...
finish = clock();
double duration = (double) (finish-start)/CLOCKS_PER_SEC; //时间以秒为单位
用法2:
#include "time.h"
... ...
cout << "Time used = " << (double)clock()/CLOCKS_PER_SEC << "s\n"; //时间以秒为单位
c#计时器
System.Diagnostics.Stopwatch Time = new System.Diagnostics.Stopwatch();
Time.Start();
... ...
Time.Stop();
Console.WriteLine("用时1:{0}", Time.Elapsed.TotalSeconds);
Time.Restart(); //继续计时
Console.WriteLine("用时1、2:{0}", Time.Elapsed.TotalSeconds);
Time.Reset(); //重置
Time.Start();
... ...
Console.WriteLine("用时3:{0}", Time.Elapsed.TotalSeconds);