more useful options | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Don't be a litterbugDon't waste memory just because it seems computers have large memory spaces. Similarly, don't abuse CPU cycles, intentionally use bad algorithmns, .... Comprehensible code is always the priority, but keep an eye out for opportunities for efficiency; avoid wasteful techniques. In particular, avoid things that are silly, wasteful, meaningless, and don't contribute to effectiveness. I am especially irritated when programmers pass an array or hash reference into a routine, then copy it to a real array or hash. If the object is known always to be small, you could consider copying the whole thing into the routine.... but what if someone decides to use your routine for a much larger data set. Instead of copying data, learn to use the arrow to dereference array references. It isn't so difficult! Don't sweat the small stuffIf it's never going to affect more than 0.01%, who cares how efficient or inefficient it is? Figure out your prioritiesLet's say an object/structure takes up 128 bytes. If we have a loop which iterates a million times, options include:
Option 1 involves a million allocations and a million de-allocations, all of which take time, but requires only 128 bytes at any one time. Option 2 takes a million allocations and no de-allocations, so that saves some time. On the other hand, it requires 128,000,000 bytes of memory. How much time will be used in swapping memory to disk? Option 3 uses only a single alloaction and deallocation, and takes only 128 bytes, but there is a risk for unclear code in the procecss of saving memory. Don't optimize too earlyThe first priority is to develop a program which is complete and correct. Then you can profile the system to consider whether it could be better. -- In reply to Re: Is it wrong?
by TomDLux
|
|