00001 #include <windows.h>
00002 #include <stdio.h>
00003
00004 static LONGLONG usTicks, msTicks;
00005
00006 LONGLONG __cdecl TimeCounter_read(void)
00007 {
00008 LARGE_INTEGER ret;
00009 QueryPerformanceCounter(&ret);
00010
00011 return ret.QuadPart;
00012 }
00013
00014 LONGLONG TimeCounter_init()
00015 {
00016 LARGE_INTEGER ret;
00017
00018 QueryPerformanceFrequency(&ret);
00019 msTicks = ret.QuadPart / 1000;
00020 usTicks = msTicks / 1000;
00021
00022 return msTicks;
00023 }
00024
00025 LONGLONG TimeCounter_getDiffInUs(LONGLONG countEnd, LONGLONG countStart) {
00026 LONGLONG ret;
00027
00028 ret = countEnd - countStart;
00029 ret /= usTicks;
00030
00031 return ret;
00032 }
00033
00034 LONGLONG TimeCounter_getDiffInMs(LONGLONG countEnd, LONGLONG countStart) {
00035 LONGLONG ret;
00036
00037 ret = countEnd - countStart;
00038 ret /= msTicks;
00039
00040 return ret;
00041 }
00042
00043 char* TimeCounter_toUsString(LONGLONG count) {
00044 char *ret = new char[20];
00045 if(count > 1000000L) {
00046 count /= 1000L;
00047 if(count > 1000000L) {
00048 count /= 1000L;
00049 if(count > 7200L) {
00050 count /= 60L;
00051 if(count > 60L * 48L) {
00052 count /= 60L;
00053 sprintf_s(ret, 20, "%I64u h", count);
00054 }else sprintf_s(ret, 20, "%I64u min", count);
00055 } else sprintf_s(ret, 20, "%I64u s", count);
00056 } else sprintf_s(ret, 20, "%I64u ms", count);
00057 } else sprintf_s(ret, 20, "%I64u us", count);
00058
00059 return ret;
00060 }
00061
00062 char* TimeCounter_toMsString(LONGLONG count) {
00063 char *ret = new char[20];
00064 if(count > 1000000L) {
00065 count /= 1000L;
00066 if(count > 7200L) {
00067 count /= 60L;
00068 if(count > 60L * 48L) {
00069 count /= 60L;
00070 sprintf_s(ret, 20, "%I64u h", count);
00071 }else sprintf_s(ret, 20, "%I64u min", count);
00072 } else sprintf_s(ret, 20, "%I64u s", count);
00073 } else sprintf_s(ret, 20, "%I64u ms", count);
00074
00075 return ret;
00076 }