voku1987

io_speed_buffer.c

May 6th, 2012
298
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/times.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <stdlib.h>
  7.  
  8. #define MAX_PUFFER_GROESSE 1<<14
  9. // Ausgabe
  10. static void zeit_ausgabe(long int puff_groesse, clock_t realzeit, struct tms *start_zeit, struct tms *ende_zeit, long int schleiflaeufe);
  11.                        
  12. int main(void) {
  13.     char puffer[MAX_PUFFER_GROESSE];
  14.     ssize_t n;
  15.     long int i, j=0, puffer_groesse, opt_puffer;
  16.     struct tms start_zeit, ende_zeit;
  17.     static long ticks=0;
  18.     clock_t uhr_start, uhr_ende, system_cpu=0.0;
  19.  
  20.     // Ausgabe 
  21.     fprintf(stderr, "+--------------+-------------+--------------+--------------+--------------+\n");
  22.     fprintf(stderr, "| %-10s | %-10s | %-10s | %-10s | %-10s |\n",
  23.                     "Puffer-", "UserCPU", "SystemCPU", "Gebrauchte", "Schleifen-");
  24.     fprintf(stderr, "| %10s | %10s | %10s | %10s | %10s |\n",
  25.                     " groesse", " (Sek)", " (Sek)", " Uhrzeit", " laeufe");
  26.     fprintf(stderr, "+--------------+-------------+--------------+--------------+--------------+\n");
  27.  
  28.     while (j <= 14) {
  29.         i=0;
  30.         puffer_groesse=1<<j;
  31.         if (lseek(STDIN_FILENO, 0L, SEEK_SET) == -1) {
  32.             fprintf(stderr, "Error: lseek");
  33.             exit(1);
  34.         }
  35.         if (lseek(STDOUT_FILENO, 0L, SEEK_SET) == -1) {
  36.             fprintf(stderr, "Errir: lseek");
  37.             exit(1);
  38.         }
  39.         if ( (uhr_start = times(&start_zeit)) == -1) {
  40.             fprintf(stderr, "Error: times");
  41.             exit(2);
  42.         }
  43.         while ( (n=read(STDIN_FILENO, puffer, puffer_groesse)) > 0) {
  44.             if (write(STDOUT_FILENO, puffer, n) != n) {
  45.                 fprintf(stderr, "Error: write");
  46.                 exit(3);
  47.             }
  48.             i++;
  49.         }
  50.         if (n < 0) {
  51.             fprintf(stderr, "Error: read");
  52.             exit(4);
  53.         }
  54.         if ( (uhr_ende = times(&ende_zeit)) == -1) {
  55.             fprintf(stderr, "Error: times");
  56.             exit(5);
  57.         }
  58.        
  59.         if (ticks == 0) {
  60.             if ( (ticks = sysconf(_SC_CLK_TCK)) < 0) {
  61.                 fprintf(stderr, "Error: sysconf");
  62.                 exit(6);
  63.             }
  64.         }
  65.         // Ausgabe
  66.         zeit_ausgabe(puffer_groesse, uhr_ende-uhr_start, &start_zeit, &ende_zeit, i);
  67.         j++;
  68.     }
  69.     exit(0);
  70. }
  71.  
  72. // Ausgabe
  73. static void zeit_ausgabe(long int puff_groesse, clock_t realzeit, struct tms *start_zeit, struct tms *ende_zeit, long int schleiflaeufe) {
  74.     static long ticks=0;
  75.     if (ticks == 0) {
  76.         if ( (ticks = sysconf(_SC_CLK_TCK)) < 0) {
  77.             fprintf(stderr, "Error: sysconf");
  78.             exit(6);
  79.         }
  80.     }
  81.     fprintf(stderr, "| %10ld | %10.2f | %10.2f | %10.2f | %10ld |\n", puff_groesse, (ende_zeit->tms_utime - start_zeit->tms_utime) / (double)ticks, (ende_zeit->tms_stime - start_zeit->tms_stime) / (double)ticks, realzeit / (double)ticks, schleiflaeufe);
  82.     return;
  83. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×