Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/times.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #define MAX_PUFFER_GROESSE 1<<14
- // Ausgabe
- static void zeit_ausgabe(long int puff_groesse, clock_t realzeit, struct tms *start_zeit, struct tms *ende_zeit, long int schleiflaeufe);
- int main(void) {
- char puffer[MAX_PUFFER_GROESSE];
- ssize_t n;
- long int i, j=0, puffer_groesse, opt_puffer;
- struct tms start_zeit, ende_zeit;
- static long ticks=0;
- clock_t uhr_start, uhr_ende, system_cpu=0.0;
- // Ausgabe
- fprintf(stderr, "+--------------+-------------+--------------+--------------+--------------+\n");
- fprintf(stderr, "| %-10s | %-10s | %-10s | %-10s | %-10s |\n",
- "Puffer-", "UserCPU", "SystemCPU", "Gebrauchte", "Schleifen-");
- fprintf(stderr, "| %10s | %10s | %10s | %10s | %10s |\n",
- " groesse", " (Sek)", " (Sek)", " Uhrzeit", " laeufe");
- fprintf(stderr, "+--------------+-------------+--------------+--------------+--------------+\n");
- while (j <= 14) {
- i=0;
- puffer_groesse=1<<j;
- if (lseek(STDIN_FILENO, 0L, SEEK_SET) == -1) {
- fprintf(stderr, "Error: lseek");
- exit(1);
- }
- if (lseek(STDOUT_FILENO, 0L, SEEK_SET) == -1) {
- fprintf(stderr, "Errir: lseek");
- exit(1);
- }
- if ( (uhr_start = times(&start_zeit)) == -1) {
- fprintf(stderr, "Error: times");
- exit(2);
- }
- while ( (n=read(STDIN_FILENO, puffer, puffer_groesse)) > 0) {
- if (write(STDOUT_FILENO, puffer, n) != n) {
- fprintf(stderr, "Error: write");
- exit(3);
- }
- i++;
- }
- if (n < 0) {
- fprintf(stderr, "Error: read");
- exit(4);
- }
- if ( (uhr_ende = times(&ende_zeit)) == -1) {
- fprintf(stderr, "Error: times");
- exit(5);
- }
- if (ticks == 0) {
- if ( (ticks = sysconf(_SC_CLK_TCK)) < 0) {
- fprintf(stderr, "Error: sysconf");
- exit(6);
- }
- }
- // Ausgabe
- zeit_ausgabe(puffer_groesse, uhr_ende-uhr_start, &start_zeit, &ende_zeit, i);
- j++;
- }
- exit(0);
- }
- // Ausgabe
- static void zeit_ausgabe(long int puff_groesse, clock_t realzeit, struct tms *start_zeit, struct tms *ende_zeit, long int schleiflaeufe) {
- static long ticks=0;
- if (ticks == 0) {
- if ( (ticks = sysconf(_SC_CLK_TCK)) < 0) {
- fprintf(stderr, "Error: sysconf");
- exit(6);
- }
- }
- 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);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement