time_debug.h 1.19 KB
#ifndef _TIME_DEBUG_H_
#define _TIME_DEBUG_H_
#ifdef _WIN32
//#include <windows.h>
#include <time.h>
#include <windows.h>
typedef LARGE_INTEGER	 debug_time_t;
#else
#include <sys/time.h>
typedef struct timeval debug_time_t;
#endif


#include <stdlib.h>
#include <assert.h>

/**
* @brief	Get current system time
* @details	Platform-independent
* @param[in]		curTime current time
* @return	No returns
*/
void GetTime(debug_time_t* curTime)
{
	assert(curTime);

#ifdef _WIN32
	BOOL bSu = QueryPerformanceCounter(curTime);
#else
	gettimeofday(curTime, NULL);
#endif
}

/**
* @brief	Calculate the interval time between the two input time.
* @details	Platform-independent
* @param[in]		oldTime The old time
* @param[in]		newTime The new time
* @return	The interval time, in (us)
*/
long CalcTimeDiff(debug_time_t* oldTime, debug_time_t* newTime)
{
	assert(oldTime);
	assert(newTime);

#ifdef _WIN32
	LARGE_INTEGER freqency;
	QueryPerformanceFrequency(&freqency);

	double inteval = (double)newTime->QuadPart - oldTime->QuadPart;
	inteval = inteval * 1000000 / freqency.QuadPart;
	return (long)inteval;
#else
	return ((newTime->tv_sec - oldTime->tv_sec) * 1000000 + newTime->tv_usec - oldTime->tv_usec);
#endif
}

#endif