diff options
Diffstat (limited to 'seq-read.c')
| -rw-r--r-- | seq-read.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/seq-read.c b/seq-read.c new file mode 100644 index 0000000..b9ef58b --- /dev/null +++ b/seq-read.c | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <time.h> | ||
| 4 | |||
| 5 | int | ||
| 6 | main(void) | ||
| 7 | { | ||
| 8 | clock_t start = clock(); | ||
| 9 | size_t sum = 0; | ||
| 10 | |||
| 11 | #if 0 | ||
| 12 | int ch; | ||
| 13 | while ((ch = getc(stdin)) != EOF) { | ||
| 14 | sum += (unsigned char) ch; | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #if 1 | ||
| 19 | unsigned char buffer[1024]; | ||
| 20 | size_t n; | ||
| 21 | while ((n = fread(buffer, 1, sizeof buffer, stdin)) > 0) { | ||
| 22 | for ( size_t z = 0; z != n; ++z ) { | ||
| 23 | sum += buffer[z]; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | #endif | ||
| 27 | |||
| 28 | clock_t end = clock(); | ||
| 29 | |||
| 30 | printf("Result: %zu, Duration: %.3lf sec\n", sum, (double)(end - start) / CLOCKS_PER_SEC); | ||
| 31 | |||
| 32 | return EXIT_SUCCESS; | ||
| 33 | } | ||
