fork download
  1. #define _LARGEFILE64_SOURCE
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <time.h>
  9.  
  10. #define BLOCK_SIZE 1<<20ul
  11. #define ITERATIONS 1000
  12.  
  13. int main()
  14. {
  15. char* p;
  16. FILE* f;
  17. struct timeval start, end;
  18. double delta;
  19. int fd, i, j;
  20.  
  21. p = malloc(BLOCK_SIZE);
  22. gettimeofday(&start, NULL);
  23.  
  24. // f = fopen("dummy.bin", "w");
  25. fd = open("dummy.bin", O_BINARY | O_DIRECT | O_CREAT | O_WRONLY);
  26. f = fdopen(fd, "w");
  27.  
  28. sync();
  29.  
  30. for (i = 0; i < ITERATIONS; ++i)
  31. {
  32. for (j = 0; j < BLOCK_SIZE; ++j)
  33. p[j] = ((char)i)^((char)j);
  34. fwrite(p, BLOCK_SIZE, 1, f);
  35. }
  36. fflush(f);
  37. fclose(f);
  38. free(p);
  39.  
  40.  
  41. sync();
  42.  
  43. gettimeofday(&end, NULL);
  44. delta = ((end.tv_sec * (unsigned int)1e6 + end.tv_usec) -
  45. (start.tv_sec * (unsigned int)1e6 + start.tv_usec)) / 1.e6;
  46.  
  47. printf("%.3f MB/s (%i Mb in %.2fs)\n", ITERATIONS / delta, ITERATIONS, delta);
  48.  
  49. return 0;
  50. }
  51.  
  52.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:22: warning: implicit declaration of function ‘gettimeofday’
prog.c:25: error: ‘O_BINARY’ undeclared (first use in this function)
prog.c:25: error: (Each undeclared identifier is reported only once
prog.c:25: error: for each function it appears in.)
prog.c:25: error: ‘O_DIRECT’ undeclared (first use in this function)
prog.c:34: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
stdout
Standard output is empty