LARGE_INTEGER countstart_for; LARGE_INTEGER countend_for; __int64 timediff_for; LARGE_INTEGER frequent_for; double dsec_max = 0; double dsec_min = 0; QueryPerformanceCounter(&countstart_for); TRACE("Timer (for) Started !/n"); for (long i = 0; i< 10000; i++) { LARGE_INTEGER countstart; LARGE_INTEGER countend; __int64 timediff; LARGE_INTEGER frequent; QueryPerformanceCounter(&countstart); TRACE("Timer Started !/n"); TODO: 在此处为应用程序的行为编写代码。 _tsetlocale(LC_ALL, _T("")); //char * wsabuff = "中fadfdf国人"; char * wsabuff = "楓谷測試"; // Convert ANSI to Unicode //第一步取得需要转换的字符的长度 unsigned long lLen = strlen(wsabuff); //第二步取得转换成WCHAR,所需要的字符数 int cch = MultiByteToWideChar(CP_ACP,0, wsabuff, lLen, NULL, 0); //第三步定义数组并清零 WCHAR * wszBuffer = new WCHAR[cch + 1]; ZeroMemory((char *)wszBuffer, (cch+1)*sizeof(wszBuffer[0])); //第四步转换 MultiByteToWideChar( CP_ACP, 0, wsabuff, lLen + 1, wszBuffer, cch); TRACE(L"%s/n", wszBuffer); BYTE charUTF8[200]; ZeroMemory(charUTF8, 200); WideCharToMultiByte(CP_UTF8, 0, wszBuffer, -1, (LPSTR)charUTF8, 200, NULL, NULL ); delete [] wszBuffer; CString str = L"123, 456789, 1223, 0000-88191463 13000000000"; CString strToken = L", "; int nStartIndex = 0; for (int nEndIndex=0;nEndIndex = str.Find(strToken, nStartIndex), nEndIndex >=0 ; nStartIndex = nEndIndex + strToken.GetLength()) { CString strTemp = str.Mid(nStartIndex, nEndIndex - nStartIndex); //TRACE(L"%s/r/n", strTemp); } CString strTemp = str.Mid(nStartIndex); TRACE(L"%s/r/n", strTemp); QueryPerformanceCounter(&countend); timediff = (__int64)countend.QuadPart-(__int64)countstart.QuadPart; QueryPerformanceFrequency(&frequent); double dsec = (double)timediff/(double)frequent.QuadPart; TRACE("Timer End. Elapsed time:%f(second)/n",dsec); if (dsec < dsec_min || dsec_min == 0) dsec_min = dsec; if (dsec > dsec_max || dsec_max == 0) dsec_max = dsec; } QueryPerformanceCounter(&countend_for); timediff_for = (__int64)countend_for.QuadPart-(__int64)countstart_for.QuadPart; QueryPerformanceFrequency(&frequent_for); double dsec_for = (double)timediff_for/(double)frequent_for.QuadPart; TRACE("Timer (for) End. Elapsed time:%f(s), min=%f(s), max=%f(s)/n",dsec_for, dsec_min, dsec_max); 精确计算代码执行的时间差。