Ok, as a start I'll begin with this (no compiler optimisations)
Code:
//=========== Start of challenge code =========
int c;
while((c = getc(f)) != EOF) {
if (isalpha(c)) {
int lc = tolower(c);
int iv = lc == 'e' || lc == 'a' || lc == 'o' || lc == 'i' || lc == 'u';
vowelCount += iv;
conCount += !iv;
}
}
//=========== End of challenge code =========
The original code:
Code:
$./a.out
There are 2357034 consonants and 1433891 vowels in the Complete Works of William Shakespeare
Time taken = 102125 microseconds
My modified code:
Code:
$ ./a.out
There are 2357034 consonants and 1433891 vowels in the Complete Works of William Shakespeare
Time taken = 32977 microseconds
Only optimisation I made, really, is ordering the checks for a vowel based on English vowel frequency; i.e. I'm not concerned about much, right now, apart from how often vowels appear in typical English text. So, no real code changes but an improvement.
Edit: So I guess I didn't optimise it at all. Or did I?
Edit2: meh... compiler optimisations were turned off. My bad. My non-code-related changes are still faster with -O2 though.