Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Don't be a litterbug

Don'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 stuff

If it's never going to affect more than 0.01%, who cares how efficient or inefficient it is?


Figure out your priorities

Let's say an object/structure takes up 128 bytes. If we have a loop which iterates a million times, options include:

  1. allocate, use,and deallocate a million objects
  2. allocate, and use a million objects without deallocating them
  3. allocating one object, using it a million times to store different data, then de-allocate once.

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 early

The 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.

--
TTTATCGGTCGTTATATAGATGTTTGCA


In reply to Re: Is it wrong? by TomDLux
in thread Is it wrong? by Drgan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-24 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found