Hello,
I was trying to implement toupper() functionality using bitwise operations (assuming only alphabets as input).
It works. The thing that I am not getting is that it's execution time is 0.031s.
But when I used library function toupper() to implement the same functionality, its execution time is almost 0.000s. I thought my bitwise implementation would be faster, as it is avoiding many other overheads like function call, no if-else check for alphabets (as i've assumed input would always be alphabets) etc. Can someone explain why so?
I'm using CodeBlocks 8.02 IDE with GNU GCC Compiler.
I was trying to implement toupper() functionality using bitwise operations (assuming only alphabets as input).
Code:
#include <stdio.h>
#include <ctype.h>
int main()
{
int i=0;
unsigned int mask = ~32;
char buffer[512] = "Hello there THis IS better Than THE Best";
printf("%s\n",buffer);
while(buffer[i]!='\0')
printf("%c",mask & buffer[i++]); //// Slow
// printf("%c",toupper(buffer[i++])); //// Fast....why?
return 0;
}
But when I used library function toupper() to implement the same functionality, its execution time is almost 0.000s. I thought my bitwise implementation would be faster, as it is avoiding many other overheads like function call, no if-else check for alphabets (as i've assumed input would always be alphabets) etc. Can someone explain why so?
I'm using CodeBlocks 8.02 IDE with GNU GCC Compiler.
Comment