Marshall:

Your experience of 3x-10x:1 feels about right to me.

Regarding assembly language: I'll have to agree ... mostly.

For embedded systems with small processors, you can still beat a compiler once you know enough about the chip and the application. On larger computers with modern CPUs, when starting from scratch, you're dead on--it's hard to beat a good compiler. However, when I dive into assembly language on a modern CPU, I don't start from scratch, I let the compiler generate the first pass for me. Then I dig into the processor manuals, and examine the algorithm and then improve the code from there. (And only if I can find a bottleneck I can reasonably expect to improve.)

When I started programming in assembler (Z-80, 6502, 68000, 8051 days), it was easy to beat a compiler because compilers weren't that good (generally), and the CPU timings were easy to understand. You could read the instruction timings and generally have a good shot at improving the speed on your first attempts. This is still true on most small embedded systems (AVR, PIC, etc.).

Once caching became popular, things started to get "interesting". You had to understand how your code, the cache and history affected things. With caching, the timings became a bit trickier, as code and data access speed changed. So you could make a decent guess about how to improve the algorith, but you could easily be surprised when things didn't work the way you guessed they would. You needed more guesswork and insight into your algorithm to make significant speed improvements. So larger embedded systems using these processors (80386, ARM, etc.) are harder to improve, and the compilers for them tend to be smarter.

When the Pentium came out with the I and V pipes, things got downright hard. There was enough complexity in timing, multiple cache levels and figuring out how to maximize the use of the I and V pipelines that guessing how to improve execution speed involves a lot of guesswork. At this time, you'd have to really chew on the problem, and you had to measure things frequently. You could no longer rely on the instruction timings to get you a good guess unless you really had a feel for how everything interacted. Even then it was finicky. Of course these processors are so fast that dropping down into assembler is much less common.

Now with speculative execution, branch prediction, etc., I'm not sure I could beat a compiler. And even if I did, it would be the result of many guesses and experiments. I've not had a need to improve the code for any CPU more advanced than a Pentium II, so I don't know how much more difficult it is to optimize code in that environment. I guess I'll have to find some time to play around with my Atom, Athlon XP and Pentium IV computers and see what I can do...

And I've totally ignored the introduction of multitasking, too. Once that came in, you had no idea how other applications were going to impact yours. Compilers, too, became a lot better. Now, on the (very rare) occasions when I drop into assembly, it's either an embedded system that's easy to understand and where I *truly* need the speed, or it's just (a) pure fun, (b) a challenge for myself, and/or (c) an exercise to keep myself sharp.

...roboticus


In reply to Re^4: Simple line parse question by roboticus
in thread Simple line parse question by jimmy.pl

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.