• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

perl vs. c - why perl??

CTho9305

Elite Member
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.
 
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.
 
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.
 
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.
 
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!
 


<< 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 😉
 
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.
 
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.
 
Back
Top