[UPHPU] Rails vs PHP
Walt Haas
haas at xmission.com
Tue Mar 27 09:52:17 MDT 2007
On Tue, 2007-03-27 at 08:01 -0700, Joshua Simpson wrote:
> The assembly code generated by modern compilers outmatches nearly any
> handwritten assembly most people can come up with. It's a common fallacy
> nowadays that human generated asm is superior in speed for most things;
> that used to be the case, but now that compilers have evolved to the point
> where they are today, it's pointless to write in assembly for most
> performance reasons.
Negatory. We still have to hand-code assembler for a few very specific
tasks, the kind of code that is very tightly coupled to a specific
specialized chip. In fact doing that is pretty common practice in the
embedded systems field (where I have spent most of my life).
The strategy that I have adopted successfully over the years is to
develop in the following steps:
1) Get the algorithm right. The "right" algorithm is the algorithm that
does the best job of solving the problem, including the corner cases and
unusual situations. At this stage of development we don't worry about
performance at all, the goal is to write code that is readable,
maintainable and correct.
2) With the right algorithm coded and tested, we next profile it to see
where the hot spots are. This usually identifies 5%-10% of the code in
some tight loop somewhere.
3) We turn on whatever compiler optimizations, op code caching or
whatever tuning is available for that language to try to get the
execution speed in the hot spots up to what is needed.
4) If performance meets spec, or is limited by something else (like a
communications link), we're done.
5) If we still need more speed in the hot spot, we get serious about
making the code run faster. Maybe recoding the hot spot in C is enough
to get the job done. Or maybe we switch to a specialized compiler that
generates code optimized for the chip, say the Intel compiler for the
Intel chip rather than gcc, since the design goal of gcc is generality
rather than highly optimized object code. In the case of a tight loop
that exchanges data with, say a DSP chip, we may decide to use
assembler. Compilers only tune for general problems. You can't
reasonably expect a compiler to be able to generate the right
instructions for an unusual chip, so we may end up doing it by hand.
Believe me, I don't use assembler unless I need to. But sometimes I
need to.
-- Walt
More information about the UPHPU
mailing list