in reply to Which way is faster?
1. 98.765% of all programming task do not need a special focus on the fastest code.
2. Most times the compiler does a better optimization job than you. (What does the Perl interpreter?)
3. It is more important to spend time on a clean program structure to enable support.
Ad 1)
What type of programs or script does the normal human write? Does it really matter if a script finishes after 5 minutes or 4min55 ? If an optimization gives 3m to a program, it was formerly bad designed and should not be optimized, but restructured. Maybe GUI-callbacks to verify an entry? If you check every field against a database it will be slow, but as above, redesign not optimization is necessary. The rest are special cases, like games, os-kernels, often/many running scripts, Perl interpreters etc.
Ad 2)
Since the time I analyzed assembler output of a C compiler to find bugs in the RT-Library, I leave most things to the compiler. It made no difference wether to dereference a pointer over some levels or use a local variable and one line of code more, both resulted in the same code using CPU registers. (Any knowledge, what Perl does?) But the second version was readable, this leads to my next point!
ad 3)
Optimized code is most times only readable with the help of the brains who invented that. What if he is not available (well, my experience is that it is most times he, not she) or can't remeber what he thought 6 months ago? Invest weeks to fix a bug? Throw away the code and rewrite it? What estimation do you give your customer, what to your boss about your working results? For some microseconds to rotate a logfile? If you write clean code, well structured constructs (loops) the code-flow becomes understandable and is therefore easier to maintain, which includes maybe optimization.
Oh, I forgot. Use strict, it is most times more important than your optimization, which work only without strict.
regards Brutha
Confession:
I named Basic Variables 'a1', 'a2' to let the interpreter find them faster. That was about 20 years ago on a apple][
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Structure is more important than speed
by Anonymous Monk on Sep 09, 2002 at 11:39 UTC | |
by sauoq (Abbot) on Sep 09, 2002 at 21:34 UTC | |
by Anonymous Monk on Sep 09, 2002 at 23:46 UTC | |
by sauoq (Abbot) on Sep 09, 2002 at 23:58 UTC | |
by Anonymous Monk on Sep 10, 2002 at 03:19 UTC | |
|
Re: Structure is more important than speed
by bronto (Priest) on Sep 10, 2002 at 08:26 UTC |