Blame view

src/test/time_debug.h 1.19 KB
8805b950   Liu Meng   物品遗留效果优化
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  #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