Skip to content

Instantly share code, notes, and snippets.

@tanakamura
Created January 9, 2017 15:53
Show Gist options
  • Save tanakamura/a7007346543cb6bc9fbd7e387d970404 to your computer and use it in GitHub Desktop.
Save tanakamura/a7007346543cb6bc9fbd7e387d970404 to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <time.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
double f_freq;
double
getsec(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec + ts.tv_nsec/1000000000.0;
}
int main()
{
double t0, t1;
FILE *a = fopen("a.txt", "wb");
fclose(a);
for (int i=0; i<4; i++) {
int nloop = 4096;
t0 = getsec();
for (int li=0; li<nloop; li++) {
int fd = open("a.txt", O_RDWR);
close(fd);
}
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