3 ms·
> faster with an if(b){str1}else{str2} I'm not aware of any compiler that optimises such a structure to avoid branch misprediction. An array of two strings mig
by seabee 14y ago
> faster with an if(b){str1}else{str2}
I'm not aware of any compiler that optimises such a structure to avoid branch misprediction. An array of two strings might require more bits and ops in an unoptimised interpreted language, or one in which bounds checking is always enabled, but I can assure you that an indexed load is 1 instruction and a load for each string is... well, more than that. You are right, you are definitely talking straight out of your ass!
The n-state solution is a state machine, btw - but it is right to use a simple solution if that is all your problem requires.