⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hrtimer.cpp

📁 Cryptolib4.1.rar
💻 CPP
字号:
// hrtimer.cpp - written and placed in the public domain by Wei Dai

#include "pch.h"
#include "hrtimer.h"

#ifdef HIGHRES_TIMER_AVAILABLE

#if defined(_WIN32)
#include <windows.h>
#elif defined(__unix__)
#include <sys/time.h>
#elif defined(macintosh)
#include <Timer.h>
#endif

#include <assert.h>

NAMESPACE_BEGIN(CryptoPP)

word64 Timer::GetCurrentTimerValue()
{
#if defined(_WIN32)
	FILETIME now;
	GetSystemTimeAsFileTime(&now);
	return now.dwLowDateTime + ((word64)now.dwHighDateTime << 32);
#elif defined(__unix__)
	timeval now;
	gettimeofday(&now, NULL);
	return (word64)now.tv_sec * 1000000 + now.tv_usec;
#elif defined(macintosh)
	UnsignedWide now;
	Microseconds(&now);
	return now.lo + ((word64)now.hi << 32);
#endif
}

unsigned long Timer::ConvertTo(word64 t, Unit unit)
{
	switch (unit)
	{
	case SECONDS:
		return (unsigned long)(t / (TicksPerMillisecond() * 1000));
	case MILLISECONDS:
		return (unsigned long)(t / TicksPerMillisecond());
	case MICROSECONDS:
		assert(TicksPerMillisecond() % 1000 == 0);
		return (unsigned long)(t / (TicksPerMillisecond() / 1000));
	}
	assert(false);
	return 0;
}

void Timer::StartTimer()
{
	m_start = GetCurrentTimerValue();
	m_started = true;
}

unsigned long Timer::ElapsedTime()
{
	if (m_started)
		return ConvertTo(GetCurrentTimerValue() - m_start, m_timerUnit);
	else
	{
		StartTimer();
		return 0;
	}
}

NAMESPACE_END

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -