diff options
| author | Thomas Schmucker <ts@its1.de> | 2020-06-11 18:27:39 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2020-06-11 18:27:39 +0200 |
| commit | 5b06a00890fe3e2c77c7c5835c975e87b8c7dfb0 (patch) | |
| tree | cfe688d2c6bd3116ce81bc709f13a1fa1c68a718 /seq-read.c | |
| download | libcsv-5b06a00890fe3e2c77c7c5835c975e87b8c7dfb0.tar.gz libcsv-5b06a00890fe3e2c77c7c5835c975e87b8c7dfb0.tar.bz2 libcsv-5b06a00890fe3e2c77c7c5835c975e87b8c7dfb0.zip | |
erster Commit
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 | } | ||
