perl vs. c - why perl??

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
here is one of my machines. click the first link - all it does is cat /proc/cpuinfo and replace \n with
\n. the 2nd link is the same thing, written in C++ (compiled statically since I didn't put gcc on the machine, and didn't want to update glibc to a version on the "compiling" machine).

the perl version takes 1.5 seconds (according to time), and the c++ version takes about .05 seconds. why would I use perl?

admittedly, in perl, I executed cat, whereas in C++ I just read hte file directly, but I checked both ways and the difference was negligible.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Try mod_perl, Apache compiles it at startup and it stays compiled in memory instead of being interpeted each time you ask for the CGI script.

Perl is a lot better when you don't have a 486 =) Since the startup time is much longer than a native binary.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
For a trivial (in terms of compute time) program such as this, I'd go with whatever is easier. You mentioned another reason for choosing perl ... portability.
Your script will likely run on any unix platform (although /proc/cpuinfo may not exist). The C program will, at the least, need to be recompiled.


Now when you get into large, data & computationally intensive programs, you'll see a big difference between the performance of interpreted vs. compiled languages.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Now when you get into large, data & computationally intensive programs, you'll see a big difference between the performance of interpreted vs. compiled languages.


From what I understand perl is only interpreted at startup, after it's loaded into memory it's as fast as other compiled code.
 

thornc

Golden Member
Nov 29, 2000
1,011
0
0
When the main reason to use an interpreted is that you, the programmer, don't need to handle all
of the memory allocation stuff the intrepreter will do that for you.

Perl is a good language for small projects where regular expressions are important, for anything bigger I would go
with Python. For speed C/C++ is almost mandatory. Java stays in between!
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81


<< Perl is a lot better when you don't have a 486 =) Since the startup time is much longer than a native binary. >>



right, but C is equally better. if I can handle 4 visitors/second with perl on a 486, vs. 40 with C, I can handle 4000 on an athlon vs 4000. exagerated, but the point is there ;)
 

bevancoleman

Golden Member
Jun 24, 2001
1,080
0
0
The reason to use Perl or any other scripted language is ease of use not speed.

C will always be faster then any interperated (PHP, ASP, sh, etc) or JITed languages (.Net, Java) as the compiler can spend more time in optomising the result, there is also less overhead.

Technicaly this isn't anything to do with the language but with the compiler used.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Also security, in C or C++ it's a lot easier to set yourself up for a buffer overflow somewhere and get yourself r00ted, with a language like perl or python all the memory allocation is handled by the interpreter and you can't accidentally do something like that.