Skip to content

Instantly share code, notes, and snippets.

@delamonpansie
Created July 28, 2011 08:16
Show Gist options
  • Save delamonpansie/1111192 to your computer and use it in GitHub Desktop.
Save delamonpansie/1111192 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <sys/time.h>
int main(int argc, const char *argv[])
{
if (argc > 2) {
printf("Usage: %s [count]", argv[0]);
exit(EX_USAGE);
}
char template[] = "tmpXXXXXX";
int fd = mkstemp(template);
if (fd < 0) {
perror("Unable to create temp file");
exit(EX_OSERR);
}
unlink(template);
struct timeval start, stop;
gettimeofday(&start, NULL);
int i = argc == 2 ? atoi(argv[1]) : 1000;
double count = i;
while (i-- > 0) {
(void)write(1, ".", 1);
if (write(fd, "x", 1) < 1) {
perror("write");
exit(EX_OSERR);
}
fsync(fd);
}
gettimeofday(&stop, NULL);
printf ("\nIOPS: %f\n", count * 1000000 / (1000000 * (stop.tv_sec - start.tv_sec) +
(stop.tv_usec - start.tv_usec)));
return EX_OK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment