Skip to content

Instantly share code, notes, and snippets.

@Sebbyastian
Created December 22, 2014 15:52
Show Gist options
  • Save Sebbyastian/16622d8413d91e669ab9 to your computer and use it in GitHub Desktop.
Save Sebbyastian/16622d8413d91e669ab9 to your computer and use it in GitHub Desktop.
Benchmark for @wesen
#include <assert.h>
#include <stdio.h>
int main(void) {
unsigned int criteria[2] = { 0 };
#ifndef UNBUFFERED
int n = setvbuf(stdin, NULL, _IOFBF, 65536);
assert(n == 0);
for (;;) {
int c = getchar();
if (c < 0) {
break;
}
criteria[c == 'a']++;
}
#else
char buffer[65536];
for (;;) {
size_t size = fread(buffer, 1, sizeof buffer, stdin);
if (size == 0) {
break;
}
for (size_t x = 0; x < size; x++) {
criteria[buffer[x] == 'a']++;
}
}
#endif
printf("%u %u\n", criteria[0], criteria[1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment