[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] MacPerl speed vs MachTen FORTRAN



At 8:09 PM -0800 11/18/98, Chris Nandor wrote:
>At 22.57 -0500 1998.11.18, Mamoru Yamanishi wrote:
>>Instead of this, Perl is interpreter.  Therefore, your perl script
>>cannot run directory on CPU.
>
>The fact that it is interpreted is not really why it would be slow, because
>it is, in fact, compiled.  The perl program is often called the "perl
>interpreter", but it could just as well be called the "perl compiler".
>Except now there is a separate thing called the Perl compiler.  Oh well.

I'm not sure that this really covers the situation, Chris.  Fortran
(like C) is generally compiled into machine instructions for a given
machine.  Perl is, in contrast, "pre-compiled" into a set of generic
"byte codes" (such as those used by Java or, years ago, UCSD Pascal).

So, although the Perl interpreter does not need to parse each line every
time the line is executed, it DOES have to "interpret" each byte code,
then branch off to an appropriate piece of logic.  A Fortran program, in
contrast, simply runs "natively" on the CPU.  (As I understand the Perl
Compiler, BTW, a great deal of the Perl runtime will still be present in
(linked into) any compiled program.)

Having said all this, it should be noted that SOME parts of Fortran are,
in fact, interpreted.  Specifically, format statements (as used by READ
and WRITE statements) are interpreted each time they are used.  This is
responsible for the fact that Fortran I/O (like C's, if printf or scanf
is used) is substantially slower than, say, COBOL's.

Now, let's get back to Mr. Asquith's question.  Yes, you should pre-
allocate your arrays; this will keep Perl from extending the array each
time you add an element.  No, Perl is not going to give you the same
speed as compiled Fortran.  If that's a problem, use Fortran or possibly
some sort of mixed solution (e.g., Perl scripts calling Fortran programs).

If you are doing a lot of arithmetic, and integers will suit your needs,
you might try telling Perl to use integer arithmetic.  It's not clear to
me that this will help, but it might be worth a try...

-r
Rich Morin:          rdm@cfcl.com, +1 650-873-7841, http://www.ptf.com/~rdm
Prime Time Freeware: info@ptf.com, +1 408-433-9662, http://www.ptf.com
MacPerl: http://www.ptf.com/macperl,   http://www.ptf.com/ptf/products/MPPE
MkLinux: http://www.mklinux.apple.com, http://www.ptf.com/ptf/products/MKLP

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch