[Beowulf] C vs C++ challenge

Matt Valerio m-valerio at onu.edu
Tue Feb 24 08:13:12 EST 2004


Hello,

I'm an avid C++ programmer myself, and C++ is definitely my choice of the 2
languages.

That being said, I think it would be interesting to see what the creator of
both C and C++ has said about the two.  I ran across this interview with
Bjorn Stroustrup at
http://www.phy.duke.edu/brahma/Resources/c++_interview/c++_interview.html.

Like anything on the internet, it should be taken with a grain of salt.  Can
anyone vouch for its validity, or is it a hoax to get us to all hate C++ and
stick with C?

-Matt






-----Original Message-----
From: beowulf-admin at scyld.com [mailto:beowulf-admin at scyld.com] On Behalf Of
Jakob Oestergaard
Sent: Tuesday, February 24, 2004 4:36 AM
To: Beowulf
Subject: Re: [Beowulf] C vs C++ challenge

On Sun, Feb 01, 2004 at 02:57:37AM -0800, Trent Piepho wrote:
> > I could easily optimize it more (do the work on a larger buffer at a
> > once), but I think enough waste heat has been created here.  This is a
> > simple 2500+ Athlon XP box (nothing fancy) running 2.4.24-pre3.
> 
> Enough time wasted on finding different solutions to a simple problem?
Surely
> not.  Let me toss my hat into the ring:
...

Hi guys!

Guess who's back - yes, it's your friendly neighborhood language
evangelist :)

I said I'd be gone one week - well, I put instant coffe in the
microwave, and *wooosh* went three weeks ahead in time.

What a fantastic thread this turned into - awk, perl, more C, java and
God knows what.  I'm almost surprised I didn't see a Fortran
implementation.

See, I was trying to follow up on the challenge, then things got
complicated (mainly by me not being able to get the performance I wanted
out of my code) - so instead of flooding your inboxes, I wrote a little
"article" on my findings.

It's up at:
 http://unthought.net/c++/c_vs_c++.html

Highlights:
 *) Benchmarks - real numbers.
 *) A C++'ification of the fast C implementation (that turns out to be
    negligibly faster than the C implementation although the same
    algorithm and the same system calls are used), which is generalized
    and generally made usable as a template library routine (for
    convenient re-use in other projects - yes, this requires all that
    boring non-sexy stuff like freeing up memory etc.)
 *) Two new C++ implementations - another 15 liner that's "only" twice
    as slow as the C code, and another longer different-algorithm C++
    implementation that is significantly faster than the fastest C
    implementation (so far).

Now, I did not include all the extra implementations presented here. I
would like to update the document with those, but I will need a little
feedback from various people.

First; how do I compile the java implementation?  GCC-3.3.2 gives me
----------------------------------------------------------------
[falcon:joe] $ gcj -O3 -march=pentium2 -Wall -o wc-java wordcount.java
wordcount.java: In class `wordcount':
wordcount.java: In method `wordcount.main(java.lang.String[])':
wordcount.java:18: error: Can't find method `split(Ljava/lang/String;)'
in type `java.util.regex.Pattern'.
                   words = p.split(s);
                            ^
1 error
----------------------------------------------------------------

Second; another much faster C implementation was posted - I'd like to
test against that one as well. I'm curious as to how it was done, and
I'd like to use it as an example in the document if it turns out that it
makes sense to write a generic C++ implementation of whatever algorithm
is used there.  Well, if the code is not a government secret   ;)

So, well, clearly my document isn't completely updated with all the
great things from this thread - but at least I think it is a decent
reply to the mail where the 'programming pearl' C implementation was
presented.

I guess this could turn into a nice little reference/FAQ/fact type of
document - the oppinions stated there are biased of course, but not
completely unreasonable in my own (biased) oppinion - besides, there's
real-world numbers for solving a real-world problem, that's a pretty
good start I would say  :)

I'd love to hear what people think - if you have the time to give it a
look.

Let me know, flame away, give me Fortran code that is faster than my
'ego-booster' implementation at the bottom of the document!  ;)

Cheers all :)

 / jakob

BTW: Yes, I had a great vacation;
   http://unthought.net/avoriaz/p1010050.jpg  ;)

_______________________________________________
Beowulf mailing list, Beowulf at beowulf.org
To change your subscription (digest mode or unsubscribe) visit
http://www.beowulf.org/mailman/listinfo/beowulf

_______________________________________________
Beowulf mailing list, Beowulf at beowulf.org
To change your subscription (digest mode or unsubscribe) visit http://www.beowulf.org/mailman/listinfo/beowulf



More information about the Beowulf mailing list