I've seen all kinds of code on perlmonks, and it appears to me that there are definitely different types of efficiency, when it comes to evaluating whether or not code is "good".

To put it another way, I guess you could say that when it comes to efficiency: TMTOWTDI

Though this topic has probably been discussed, I supersearched titles and didn't find that it was discussed in its own node (search:efficiency importan).

I'm going to throw out a few ideas, and anyone who wants to add to this is encouraged. This is my amateur opinion, so if some professionals want to give their views, that would be great.


Obviously, how long it takes a program to compile and execute (more importantly, to execute), is a good judgement of efficiency, in many situations.

In other situations, your efficiency could be measured by how little memory is used, or how little storage is used, or how easily your peers understand your code, (they might not be perlmonks). Another measurement of efficiency is how long it takes you to write the code (trading machine time for programmer time).

In node 326181 I wrote a script which when running a 733 or 750 AMD chip, took only a second or so to compile and execute. It produced output to a text file, within an accuracy that was customizeable within the program.

I believe that in this case, the "efficiency" of this program is better judged as the speed of transfering the output (i.e. bandwidth) or how long it would take to find information in it using an editor / browser. This is mostly because it uses a small amount of processing power and because it only needs to be run once.

(That being said, I titled the node "Percentage to Fractions", so it was good of them to post some efficient code in there, in case someone else looks for the same thing!)

An argument in favour of making any script most efficient in the traditional sense is that one day the programmer will more than likely need to write something that runs fast, so they might as well learn how to as soon as possible.

Maybe someone ought to make a node where people can post little tricks to make their programs compile faster.


In reply to Types of Efficiency by David Caughell

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.