Performance: Perl versus compiled programs

B

Ben Morrow

Apart from that, Perl programs generally have some startup cost
(parsing and compiling) that you need to factor out. If you have a
program that spends a large amount of time (relative to the startup
time) processing text, Perl might actually beat a C program.

Perl *is* a C program. Therefore is is always possible to write a C
program which will run at least as fast as any given Perl program. The
question, as always with optimization, is 'is it worth it?'. And the
answer is nearly always 'no'.

Ben
 
M

Martien Verbruggen

Perl *is* a C program. Therefore is is always possible to write a C
program which will run at least as fast as any given Perl program. The
question, as always with optimization, is 'is it worth it?'. And the
answer is nearly always 'no'.

I agree, and I hope that that sentiment was clear from the rest of
what I wrote.

Of course, you can always link in the Perl libraries, and write a C
program using the Perl internals. :)

Martien
 
A

Anno Siegel

Alan J. Flavell said:
I'm sure your answer is precisely correct: "yes, it *can*".

[good stuff snipped]
I don't myself recall a situation where an application was ever turned
from being impractical into feasible merely by recoding in a different
language. I do, however, recall an occasion where a task that needed
3 days computation was re-examined from scratch, and a totally
different algorithm was used, bringing the time down to about 20
minutes. ...

It is also common for a slow program to spend most of the time in one
or two "hot spots". With a Perl program, these can be identified by
profiling and possibly re-coded in C. Using the Inline module, this
can be done almost transparently, so you end up with something that
is structurally still a Perl program, but with nearly the speed of a
compiled binary. If your program has those hot spots, that is...

Anno
 
P

pkent

I have a PERL program that reads from a large text file and does some
processing on every line it reads. If this same program is written in
C or any other compiled language, would I get significant performance
improvement?

It's certainly possible that the perl program can be faster than the C
one. It might be _much_ faster.

OTOH it might be slower, although that might be 'a small amount slower'.
It may depend on a lot of things, including how good the C programmer is
and how good the perl programmer is.

In this scenario I guess that program will run for a relative 'long'
time, which means the startup time for perl and the compilation phase
might be relatively small, which leaves us with the runtime speed being
the deciding factor. Perl is written in C, and once a perl program has
been compiled it's full steam ahead.

I am primarily asking about whether writing a program in Perl can
cause significant performance impact.

In general, none at all, but the parameters of what is acceptable all
depend on your particular needs and circumstances (which you haven't
mentioned so I'm giving the general answer).

P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top