Skip to content

Instantly share code, notes, and snippets.

@tanakamura
Created January 9, 2017 05:37
Show Gist options
  • Select an option

  • Save tanakamura/23397b1d9de969ced2130d6ed90d8226 to your computer and use it in GitHub Desktop.

Select an option

Save tanakamura/23397b1d9de969ced2130d6ed90d8226 to your computer and use it in GitHub Desktop.
#define UNICODE
#include <windows.h>
#include <stdio.h>
double f_freq;
double
getsec(void)
{
LARGE_INTEGER v;
QueryPerformanceCounter(&v);
return v.QuadPart / f_freq;
}
int main()
{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
f_freq = freq.QuadPart;
double t0, t1;
FILE *a = fopen("a.txt", "wb");
fclose(a);
HANDLE h = CreateFile(TEXT("a.txt"),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
0,
NULL);
CloseHandle(h);
for (int i=0; i<4; i++) {
int nloop = 4096;
t0 = getsec();
for (int li=0; li<nloop; li++) {
HANDLE h = CreateFile(TEXT("a.txt"),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
0,
NULL);
CloseHandle(h);
}
t1 = getsec();
printf("%f[usec]\n", ((t1-t0)/nloop)*1000000.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment