Advertisement
DavidsonDFGL

I/O Test

Jul 25th, 2016
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #define BUFF_SIZE 250
  2. static int io_test(void)
  3. {
  4.     struct tms timing; /* Timing information. */
  5.     clock_t t0, t1;    /* Elapsed times.      */
  6.     char *buffer[BUFF_SIZE];
  7.  
  8.     /* Allocate buffer. */
  9.     for (int i = 0; i < BUFF_SIZE; i++)
  10.     {
  11.         buffer[i] = malloc(0x200000);
  12.         if (buffer[i] == NULL)
  13.         {
  14.             printf("Error %d!\n", i);
  15.             exit(EXIT_FAILURE);
  16.         }
  17.     }
  18.  
  19.     /* Fill buffer. */
  20.     t0 = times(&timing);
  21.    
  22.     for (int i = 0; i < BUFF_SIZE; i++)
  23.         for (int j = 0; j < 0x200000; j++)
  24.             buffer[i][j] = 0x7F;
  25.  
  26.     t1 = times(&timing);
  27.    
  28.     /* House keeping. */
  29.     for (int i = 0; i < BUFF_SIZE; i++)
  30.         free(buffer[i]);
  31.  
  32.     /* Print timing statistics. */
  33.     if (flags & VERBOSE)
  34.         printf("  Elapsed: %d\n", t1 - t0);
  35.    
  36.     return (0);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement