Boost timer實現

CalmReason發表於2016-08-24



#include <ctime>
using namespace std;

class timer
{
public:
	timer() { _start_time = std::clock(); } 

	void   restart() { _start_time = std::clock(); } 

	double elapsed() const                  
	{ return  double(std::clock() - _start_time) / CLOCKS_PER_SEC; }

	double elapsed_max() const
	{
		return (double((std::numeric_limits<std::clock_t>::max)())
			- double(_start_time)) / double(CLOCKS_PER_SEC);
	}

	double elapsed_min() const
	{ return double(1)/double (CLOCKS_PER_SEC); }
private:
	std::clock_t _start_time;//程式啟動時的clock數
}; 


相關文章