aboutsummaryrefslogtreecommitdiff
path: root/seq-read.c
blob: b9ef58b8d3f16033d4157ffe89dd80be576f0fbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int
main(void)
{
	clock_t start = clock();
	size_t sum = 0;

#if 0
	int ch;
	while ((ch = getc(stdin)) != EOF) {
		sum += (unsigned char) ch;
	}
#endif

#if 1
	unsigned char buffer[1024];
	size_t n;
	while ((n = fread(buffer, 1, sizeof buffer, stdin)) > 0) {
		for ( size_t z = 0; z != n; ++z ) {
			sum += buffer[z];
		}
	}
#endif

	clock_t end = clock();

	printf("Result: %zu, Duration: %.3lf sec\n", sum, (double)(end - start) / CLOCKS_PER_SEC);

	return EXIT_SUCCESS;
}