discuss-gnustep
[Top][All Lists]

## 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:

```
```<snip>
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
```second.

In the second place, once you have realised that the the benchmark is
not
measuring what it says, you then have to realise that it's not really
measuring
anything meaningful at all.  What it is actually doing is finding the
smallest
```
fibonacci number that it takes a second or more to calculate, *then* it
```is
adjusting that number in proportion to the time actually taken,
presumably
in an attempt to normalise it to the second in some way.
However, since fibonacci numbers are non-linear, the result actually
varies
in ways which are too horrible to attempt to work out.  One extra call
will
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
time
```
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
Objologist
"It had better be a pretty good meeting, to be better than no meeting
at all" -- Boyd K Packer

```

reply via email to