Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Perl vs C++

by reyjrar (Hermit)
on Oct 24, 2000 at 18:36 UTC ( #38117=perlquestion: print w/replies, xml ) Need Help??
reyjrar has asked for the wisdom of the Perl Monks concerning the following question:

So I just started a new job, and yesterday I was talking to one of my co-workers about things they want me to do. One of things he mentioned was taking Cisco logs files, and making easy to use and easy to view web graphs of those logs. So, that's easy enough, and then he said "btw, do you know C++?" and I do, though I prefer to work in perl, and he said "good, cuz these log files might be terrabytes big, and in that case we're going to need c++"
Am I wrong in thinking that doesn't matter, being that Perl is the "Practical Extraction and Reporting Language" (slap me if I messed that up) it seems like terrabyte log files are what evey perl program craves for thanksgiving dinner ? :)

Replies are listed 'Best First'.
Re: Perl vs C++
by Malkavian (Friar) on Oct 24, 2000 at 18:52 UTC
    It all depends on the time period you have for analysis of those logs, and how time critical it all is.
    C, if properly written and optimised will beat Perl, due to lower overheads.
    However, if you're doing Regexp matches on those logs (and why else would you program them??), then I think the whole thing becomes moot.
    As far as I'm aware, the C lib for pattern matching is only as fast as the Perl one. The advantages gained by using C become almost insignificant.
    Looking at the spec of this, I'd go for Perl. It's likely to have fewer gotchas than an equivalent C program for a marginal extra system overhead.
    And if, once you've proved the system, they want more and faster, then, Perl has just made an excellent prototyping language.

    Just my tuppence worth. :)


    *I lost my .sig. Do you have a spare?*
RE: Perl vs C++
by merlyn (Sage) on Oct 24, 2000 at 23:23 UTC
    Tell him you'll write a prototype in Perl, and if that turns out not to be fast enough, you'll recode the critical parts in C, thanks to Perl's sophisticated interlanguage binding and runtime profiling tools.

    -- Randal L. Schwartz, Perl hacker

      HEHEHEHE, ok, I am going to take a few --'s for posting such a vapid post... but hot damn. I cracked up when I read this... that is SUCH a great way to sneak Perl into an organization.

      Geek talking to manager...

      "Don't worry, we won't be using any of those dirty open source tools here for our production system, we're just using them to prototype..."

      6 weeks later...

      "It turns out that Perl was 5 times faster and I was able to do it in 1/3rd the time... maybe we should extend your great vision in alowing me to use open source to prototype to our production environment, thereby showing a cost savings and helping our company!"

      hehehehe... that's just eeeeeevil ++'s for merlyn
RE: Perl vs C++
by eduardo (Curate) on Oct 24, 2000 at 22:40 UTC
    Alright, I've damned near gotten tired of this argument. Every single time I hear someone say: "that problem is too big for Perl, we're gonna have to throw C++ at it" I get sick to my stomach because I know that the moment I look the person in the eyes and say: "gee, does that mean that we are going to be ignoring the Von-Neumann bottleneck today?" I am going to discover that their IT training is at best abysmal. I am so very tired of people repeating things that they've "heard" from "this guy that knows a whole bunch about 'puters" so it must be true.

    Plain and simple, for 99% of server log processing tasks that *I* have encountered, no matter what the size of the datafile, the bottleneck isn't going to be the processing of the data, it is going to be the IO caused by the reading and writing of said data, and that is in Perl, as it is in C++ a very optimized streamlined operation, only a few steps removed from a stdlib call.

    Do the math, the time required for processing in memory of the lines that you read efficiently (i suggest looking into some of the block buffered reading hacks that we've discussed on this site this one was quite useful to us...) will greatly be outstripped by the time it simply takes to get the information in memory in the first place, reguarless of the language used to manipulate it (C, C++, or ASM aren't going to make your hard drive faster...) But having parsed data files approaching the terabyte size limit in *extremely* reasonable times, I have to tell you that I feel that Perl is more than qualified for 99% of these jobs.

(tye)Re: Perl vs C++
by tye (Sage) on Oct 24, 2000 at 22:11 UTC

    Perl can be faster at reading than C using stdio. I haven't timed C++ using std:: I/O against C's stdio nor against Perl's I/O, so I can't say for sure, but I suspect that Perl can be faster than C++. Unfortunately, Perl for Linux is not properly optimized and so Perl's <STDIN> is about four-times slower than it should be.

    Now, if the analysis required building data structures whose complexity was a function of the size of the log file, then I'd definitely have doubts about being able to do the analysis easily in Perl without running out of swap space (and running at a snail's pace before failing due to excessive page faulting). (Perl has a strong preference to consuming RAM in order to improve execution speed.) But that seems a very unlikely type of analysis.

    So I'd have a very strong preference for doing this stuff in Perl unless you can dig up a more concrete reason why Perl isn't appropriate. A terrabyte log file in itself isn't a reason to not use Perl.

            - tye (but my friends call me "Tye")
Re: Perl vs C++
by AgentM (Curate) on Oct 24, 2000 at 19:25 UTC
    I agree with Malkavian that it size of file will not inherently matter, but if you want truly optimized I/O, you'll be wanting to use threaded I/O and Perl's Lousy Threads are not the way to go. If you decide not to use threads, then by all means USE PERL!
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
RE: Perl vs C++
by extremely (Priest) on Oct 25, 2000 at 11:36 UTC
    Tell him both Perl and C++ are written in C so they will be the same speed =) (It's his logic, use it against him!)

    $you = new YOU;
    honk() if $you->love(perl)

RE: Perl vs C++
by Anonymous Monk on Oct 24, 2000 at 23:01 UTC
    May I suggest you either a.) Smack him upside the head or, b.) Just do it with the proper tool (Perl) and let him think you are just damn good!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://38117]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-06-20 02:42 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.