[Asterisk-Dev] PERL vs C

Nick Bachmann asterisk at not-real.org
Wed Dec 29 23:53:30 MST 2004


atif wrote:

>  Asterisk Prepaid application written in C is better than written in
>  PERL.

The name of the language is Perl... goodness knows I write enough of it 
to know...
[Which is your hint I like Perl a lot :-)]

>  C is a programming language that gives us fastest execution.

res_perl negates much of the startup speed differential by keeping a 
running interpreter.

>  PERL slower than C,

The primary spot where a performance difference will be seen is during 
startup, as I indicated above.  Perl itself is often faster than C at 
certain operations (like looping) due to optimizations that are made in 
the Perl interpreter that may not be made by the C programmer; it often 
really all comes down to who's between the keyboard and chair.

>  and regular queries are slower than stored procedures.

Definitely; but again, there is much to be said for who's writing them.  
I do think that stored procedures are underutilized for their potential; 
not only are they faster by they allow you to put database logic in the 
database and application logic in the application.  I'm a firm believer 
in "a place for everything and everything in its place."

>  Perl is a scripting/programming language which is more suitable for
>  glue logic

Yes, like interfacing databases and phone systems...

>  and applications that do not require to many resources,

And I would call prepaid pretty light on resources... we're talking 
about calling cards and database interfaces, not Fourier functions and 
hashing.

>  and need to be changed more often.

>  But it is not suited for real-time applications, though the execution
>  time for a program that does too many database queries will be
>  comparable with C since most of the overhead will be spent doing the
>  queries, we can accelerate it by using stored procedures and
>  triggers.
>
>  comments ?

What you fail to mention is that, in general, Perl is more portable and 
much easier to write and debug than C for this kind of operation, 
especially when using the many excellent modules available.  These 
modules (in general) are written by people who could write that 
particular piece of code better than you or I, which translates into 
better performance and stability.  Stored procedures, similarly, are 
less portable (and triggers make stored procs look WORA) and harder to 
debug than application-based SQL queries, which is why they're not used 
as often.

Perl is often used for this type of application because it's very fast 
to write and not too difficult to write securely--with C you have to 
worry about overflowing buffers and stacks smashed to bits.  These 
problems don't usually manifest themselves in Perl, which not only is 
reference-only (not having pointers isn't always a good thing, but 
probably is if you're just doing database code), but also has taint 
checking.

C, of course, is faster at a lot of CPU/math intensive operations, has 
cpp, does threading, and in general allows you to get much closer to the 
metal.  But for writing a prepaid app, it offers a feature set less 
optimal than Perl, in my opinion.

As there exists both app_prepaid, already written in C, and ASTCC in 
Perl, you can easily choose which paradigm you want to work with.

Nick



More information about the asterisk-dev mailing list