跳到正文

科技·工程

mytimer

zhiyin123约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年11月10日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <chrono>

#ifndef __MY_TIMER__
#define __MY_TIMER__ QwQ

namespace my{
	template <typename _Tp = double, typename _Clock = std::chrono::steady_clock>
	class timer{
private:
		typedef typename std::chrono::duration<_Tp, std::ratio<1, 1> > _Dur;
		typedef typename std::chrono::time_point<_Clock, _Dur> _Point;
        int _cnt;
		_Point _start_time;
public:
		timer() : _cnt(0), _start_time(_Clock::now()) { }
		void start() { ++_cnt; _start_time = _Clock::now(); return ; }
		_Tp duration() { _Point _end_time(_Clock::now()); return (_end_time - _start_time).count(); }
		int count() { return _cnt; }
	};
}

#endif
原文