#pragma once
#define _X_TIMER_CREATE(Alias) \
LARGE_INTEGER _d_timer_##Alias##_start_at = {0}; \
LARGE_INTEGER _d_timer_##Alias##_stop_at = {0}; \
LARGE_INTEGER _d_timer_##Alias##_time = {0}; \
UINT _d_timer_##Alias##_run_times = 0;
#define _X_TIMER_RESET(Alias) \
_d_timer_##Alias##_time.QuadPart = 0; \
_d_timer_##Alias##_run_times = 0;
#define _X_TIMER_START(Alias) \
QueryPerformanceCounter(&_d_timer_##Alias##_start_at); \
_d_timer_##Alias##_run_times++;
#define _X_TIMER_PAUSE(Alias) \
QueryPerformanceCounter(&_d_timer_##Alias##_stop_at); \
_d_timer_##Alias##_time.QuadPart += _d_timer_##Alias##_stop_at.QuadPart - _d_timer_##Alias##_start_at.QuadPart;
#define _X_TIMER_REPORT(Alias) \
TRACE(_T("xTimer[") _T(#Alias) _T("] use %d K PFT, "), _d_timer_##Alias##_time.QuadPart >> 10); \
TRACE(_T("runs %d times.\n"), _d_timer_##Alias##_run_times);
#define _X_TIMER_DECLARE(Alias) \
extern LARGE_INTEGER _d_timer_##Alias##_start_at; \
extern LARGE_INTEGER _d_timer_##Alias##_stop_at; \
extern LARGE_INTEGER _d_timer_##Alias##_time; \
extern UINT _d_timer_##Alias##_run_times;
说明:使用时候只要包只要在使用的地方将 Xtimer.h包含一下即可,使用方法如下:
_X_TIMER_DECLARE(RunTime)
_X_TIMER_CREATE(RunTime)
//_X_TIMER_RESET(RunTime)
_X_TIMER_START(RunTime)
// This is the Code which you need to get it's run time.
_X_TIMER_PAUSE(RunTime)
_X_TIMER_REPORT(RunTime)