> By better, I actually mean more efficient.
The reduced argument is why are you writing in anything other than assembler then? Mostly the answer is you don't, because it would take too long, and the result is in no way portable.
Read
this before going all gung-ho over trying to squeeze every last uS out of your code.
> I still want the most efficient solution for any problem I approach.
Unless you have an infinite amount of time, you're not going to find it. There'll always be someone else who can get that little bit extra.
Other efficiency measures:
- time it takes to write, 20 minutes (C) or a month (asm)
- time it takes to test and debug, similar extremes. Your clever asm code may be very fast, use lots of obscure technique, but if you make a mistake, you're hosed.
- time it takes to explain it to the maintenance guy, similar extremes.
You've got to run the code a hell of a lot to make several months of effort (compared to a couple of hours) pay off.
As soon as you start programming against any kind of a deadline (like professionally), then you'll realise than 99% of the program is nowhere near the program critical performance path, so busting a gut to make it microseconds quicker is a waste of effort.
Further, predicting where the performance bottleneck is is a black art, never mind the problems of figuring out the true cause.
For example, if your profile shows say strcpy() being called a lot, the answer isn't "rewrite strcpy", it's investigate why it's being called so many times in the first place. The fastest code of all is the code which isn't called.
Single function quiz assignments on the other hand are much easier to write, and much easier to profile. With some skill, and plenty of time, you can usually make a pretty "optimal" job, in terms of run-time performance.
> I actually think that things like Top Coder can be a bad influence
Probably because something like "performance" is dead easy to measure. All you need is a clock to time it, and 'diff' to compare the outputs.
Measuring "code quality" is an altogether different prospect, one which machines are currently useless at. Nor are they capable of measuring with any accuracy the amount of effort spent on the program.