[Beowulf] C vs C++ challenge

Jakob Oestergaard jakob at unthought.net
Tue Feb 24 04:35:48 EST 2004

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

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:

 *) 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

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

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

More information about the Beowulf mailing list