Newsgroups: comp.lang.java,comp.lang.c++,comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!uw-beaver!uhog.mit.edu!news.mathworks.com!newsfeed.internetmci.com!csn!news-1.csn.net!torn!watserv3.uwaterloo.ca!undergrad.math.uwaterloo.ca!clgonsal
From: clgonsal@undergrad.math.uwaterloo.ca (Carl Laurence Gonsalves)
Subject: Re: Will Java kill C++?
Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
Message-ID: <Dpz6It.2An@undergrad.math.uwaterloo.ca>
Date: Tue, 16 Apr 1996 22:01:41 GMT
References: <3134D499.653E@ix.netcom.com> <4kbfn8$1bu@news1.is.net> <4kqjf6$kh0@kaiwan009.kaiwan.com> <317173F1.5790@concentric.net>
Nntp-Posting-Host: lhopital.uwaterloo.ca
Organization: University of Waterloo
Lines: 53
Xref: glinda.oz.cs.cmu.edu comp.lang.java:40974 comp.lang.c++:185093 comp.lang.smalltalk:37429

In article <317173F1.5790@concentric.net>,
Alan L. Lovejoy <alovejoy@concentric.net> wrote:
>Mike Zorn wrote:
>> 
>> In <4kbfn8$1bu@news1.is.net> mvantassel@teambca.com (Mark VanTassel) writes:
>> 
>> >"Alan L. Lovejoy" <alovejoy@concentric.net> wrote:
>> >>Bzzzt!  Not according to the benchmarks I've done.  Go benchmark the factorial or fibonacci
>> >>functions (implemented recursively) in both C and a good Smalltalk.  You are in for a big
>> >>surprise.
>
>> >I don't think this is a valid benchmark... (and I too fail to see how
>> >Smalltalk can be faster than C++ except perhaps in bizarre special
>> >cases)
>>    True, the Fibonacci and factorial are not good candidates for a
>> recursive algorithm.  (They're just taught that way because it's one
>> of the few recursive problems that we can understand in first-year
>> college courses.)
>>    On the other hand, almost any interesting program, compiled & run
>> in different languages, should be able to give a good idea of how the
>> languages compare.  For my part, I'd also like to look at the source
>> code, and know how long it took to write (and debug) the two programs.
>>    So, Alan, I guess you'll have to come up with a program for
>> Ackermann's Function in C++ and Smalltalk to satisfy the rest of us.
>> 
>> Mike Zorn      ozma@kaiwan.com   |  Thought for the day:
>>   http://www.kaiwan.com/~ozma/   |    Java is C--
>
>I did those benchmars to prove that Smalltalk message sends are faster
>than c function calls.  To do that, I needed a benchmark that consisted
>mostly of function calls/message sends--and involved as little other
>code as possible.  The recursive factorial and fibonacci functions
>meet those requirements better than anything else I could think of.

Both factorial and fibonacci are tail-recursive, which means that your
translator may be doing tail recursion elimination, folding your n message
sends (or function calls) down to one (plus a loop). 

I don't know of any C compilers that do tail recursion elimination. I
don't know enough about the workings of Smalltalk to say for sure, but it
may be possible that your translator is doing tail recursion elimination,
thereby making message sends seem to be a heck of a lot more efficient
than they really are.

Try doing a similar test with functions that aren't tail-recursive. Or at
least find out if your Smalltalk translator may be doing tail-recursion
elimination.

-- 
        Carl Laurence Gonsalves - clgonsal@undergrad.math.uwaterloo.ca
                   Computer Science, University of Waterloo
               http://www.undergrad.math.uwaterloo.ca/~clgonsal/
                   http://www.csclub.uwaterloo.ca/~clgonsal/
