[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C and Smalltalk; speed of message send

From: Travis Griggs
Subject: Re: Objective-C and Smalltalk; speed of message send
Date: Tue, 10 Aug 2004 09:47:56 -0700

On Aug 8, 2004, at 12:07 AM, Richard Frith-Macdonald wrote:

Absolutely no offence intended but ... it's not so much that it's not a
fair test,
 rather it is a really bad benchmark.

I ran the ObjC benchmark on my system, and found that it reported about
 290,000 function calls per second and about 1,600,000 method sends
 per second ... since it's obviously ridiculous to say that a method
send is
three times as fast as a function call, I looked at the code with a bit
of care ...

In the first place, the output messages saying calls/sec or sends/sec
 are not
telling the truth, as the benchmark is not measuring calls or sends per

In the second place, once you have realised that the the benchmark is
 measuring what it says, you then have to realise that it's not really
anything meaningful at all.  What it is actually doing is finding the
fibonacci number that it takes a second or more to calculate, *then* it
 adjusting that number in proportion to the time actually taken,
in an attempt to normalise it to the second in some way.
 However, since fibonacci numbers are non-linear, the result actually
 in ways which are too horrible to attempt to work out.  One extra call
 increase the result by roughly 50%, while depending on the actual time
taken, the final adjustment can leave the result unchanged or halve it,
 and these two fluctuations are unlinked.

I changed the code to print out the input to the fib function and the
actually taken .. which gives you a more reasonable idea of performance.

As you can see, the extra information makes it clear that function calls
 are significantly faster than method sends, and the original output
 values are bogus.

Do real world examples count then? For a while we've considered porting a straight C processing application upward into Objective-C. One of the things we wanted to do was use a Dictionary (NSMutableDictionary) to store arbitrarily keyed tallies. This would replace an existing 2D array in strict C. We decided to use NSStrings as the keys. To maintain a backwards bridge, we took the old 2D access indices and turned them into a string. And then stored/set them in the NSMutableDictionary via those. The performance was not impressive. I got some pointers from this mailing list, which improved things. In the end, we'd squeezed out a solution which was almost 50% of the speed what VisualWorks Smalltalk did the same task in. The Smalltalk one was still 2x faster though, i never had to think about the memory management issues, and it worked the first time.

That aside, I'm still a huge Objective-C fan, and we may still go that route anyway. We're not sure how to get our semi-realtime data into/outof the Smalltalk memory model fast enough. :)

Travis Griggs
"It had better be a pretty good meeting, to be better than no meeting
at all" -- Boyd K Packer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]