summaryrefslogtreecommitdiff
path: root/hrtimer.h
blob: d05dfd10c47d18c01cb00b1e12838dcd70b5cb38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef CRYPTOPP_HRTIMER_H
#define CRYPTOPP_HRTIMER_H

#include "config.h"

NAMESPACE_BEGIN(CryptoPP)

#ifdef HIGHRES_TIMER_AVAILABLE

//! high resolution timer
class Timer
{
public:
	enum Unit {SECONDS, MILLISECONDS, MICROSECONDS};
	Timer(Unit unit, bool stuckAtZero = false)	: m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {}

	static word64 GetCurrentTimerValue();	// GetCurrentTime is a macro in MSVC 6.0
	static unsigned long ConvertTo(word64 t, Unit unit);

	// this is not the resolution, just a conversion factor into milliseconds
	static inline unsigned int TicksPerMillisecond()
	{
#if defined(CRYPTOPP_WIN32_AVAILABLE)
		return 10000;
#elif defined(CRYPTOPP_UNIX_AVAILABLE) || defined(macintosh)
		return 1000;
#endif
	}

	void StartTimer();
	unsigned long ElapsedTime();

private:
	Unit m_timerUnit;	// HPUX workaround: m_unit is a system macro on HPUX
	bool m_stuckAtZero, m_started;
	word64 m_start;
};

#endif

NAMESPACE_END

#endif