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. clock_t before, after;
  18. double delta;
  19. int fd, i, j;
  20.  
  21. p = malloc(BLOCK_SIZE);
  22.  
  23. // f = fopen("dummy.bin", "w");
  24. fd = open("dummy.bin", O_BINARY | O_DIRECT | O_CREAT | O_WRONLY);
  25. f = fdopen(fd, "w");
  26.  
  27. sync();
  28.  
  29. before = clock();
  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. after = clock();
  44. delta = (after - before) / (double)CLOCKS_PER_SEC;
  45. printf("%.3f MB/s (%i Mb in %.2fs)\n", ITERATIONS / delta, ITERATIONS, delta);
  46.  
  47. return 0;
  48. }
  49.  
  50.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:24: error: ‘O_BINARY’ undeclared (first use in this function)
prog.c:24: error: (Each undeclared identifier is reported only once
prog.c:24: error: for each function it appears in.)
prog.c:24: 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