Yes, a pointless test.
The winner was gcc 8.2 x64load: 5ms
process: 5ms, found 76
total: 11ms
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#ifdef USE_MALLOC
#include <stdlib.h>
#endif
#pragma comment(lib, "kernel32.lib")
int __cdecl main(int argc, char **argv)
{
LONGLONG freq, t1, t2, t3;
HANDLE hFile;
QueryPerformanceFrequency((LARGE_INTEGER *) & freq);
QueryPerformanceCounter((LARGE_INTEGER*)&t1);
if ((hFile = CreateFile("chinese.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL)) == INVALID_HANDLE_VALUE)
return 1;
DWORD nRead, nMax;
nMax = GetFileSize(hFile, NULL);
#ifdef USE_MALLOC
char *pFile = malloc(nMax + 1); // malloc buffer
*(pFile + nMax) = 0; // EOF marker
#else
HANDLE hHeap = GetProcessHeap();
char *pFile = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, nMax + 1);
#endif
ReadFile(hFile, pFile, nMax, &nRead, NULL);
CloseHandle(hFile);
if (nRead != nMax) return 2;
QueryPerformanceCounter((LARGE_INTEGER*)&t2);
char *pc = pFile;
char *pKey = u8"神 說";
int nFound = 0;
char *pcs = pKey;
while(*pc) {
while(*pc) {
if (*pc++ != *pcs) {
if (!*pcs) // end of search string
nFound++;
pcs = pKey; // reset search
break;
} else pcs++;
}
}
QueryPerformanceCounter((LARGE_INTEGER*)&t3);
printf("load: %dms\n", (int)((t2-t1) * 1000 / freq));
printf("process: %dms, found %d\n", (int)((t3-t2) * 1000 / freq), nFound);
printf("total: %dms\n", (int)((t3-t1) * 1000 / freq));
return 0;
}