Skip to content

Instantly share code, notes, and snippets.

@tanakamura
Created January 19, 2017 15:31
Show Gist options
  • Save tanakamura/ca7dcb86a534dcc837da179242e287d1 to your computer and use it in GitHub Desktop.
Save tanakamura/ca7dcb86a534dcc837da179242e287d1 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;
}
void test(int SZ)
{
char data[SZ];
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
f_freq = freq.QuadPart;
double t0, t1;
FILE *a = fopen("a.txt", "wb");
fwrite(data, 1, SZ, a);
fclose(a);
HANDLE h = CreateFile(TEXT("a.txt"),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
0,
NULL);
for (int i=0; i<4; i++) {
int nloop = 4096;
t0 = getsec();
for (int li=0; li<nloop; li++) {
DWORD rdsz;
OVERLAPPED ov;
memset(&ov, 0, sizeof(ov));
ReadFile(h, data, SZ, &rdsz, &ov);
}
t1 = getsec();
printf("rd %f[usec]\n", ((t1-t0)/nloop)*1000000.0);
}
for (int i=0; i<4; i++) {
int nloop = 4096;
t0 = getsec();
for (int li=0; li<nloop; li++) {
DWORD rdsz;
OVERLAPPED ov;
memset(&ov, 0, sizeof(ov));
WriteFile(h, data, SZ, &rdsz, &ov);
}
t1 = getsec();
printf("wr %f[usec]\n", ((t1-t0)/nloop)*1000000.0);
}
CloseHandle(h);
}
int main()
{
test(1);
test(1024);
test(1024*1024);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment