[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] objective-c vs. java
From: |
Marcus G. Daniels |
Subject: |
Re: [Swarm-Support] objective-c vs. java |
Date: |
Mon, 23 Feb 2004 11:53:27 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 |
Steve Railsback wrote:
what you mean by "dynamic method dispatch"? Do you just mean using
more method calls than necessary, or using code where the method to be
called is a variable? Or something else?
Bad things are things like [self getPos] in the middle of a loop, where
getPos just returns an instance variable. The cost of looking up the
method to call is much more than the work done by the method. In those
circumstances, you want to set things up like:
id <UniformIntegerDist> dist =
[UniformIntegerDist create: globalZone
setGenerator: randomGenerator
setIntegerMin: 0
setMax: 100];
int (*func) (id obj, SEL sel) =
(int (*) (id obj, SEL sel)) [(id) dist methodFor: M(getIntegerSample)];
And call like:
for (i = 0; i < 1000000000; i++) func(dist, M(getIntegerSample))
instead of:
for (i = 0 ; i < 1000000000; i++) [dist getIntegerSample];
Some methods take long enough to run that the cost of looking up their
code isn't a factor. For example, the same code with doubles instead
of integers will spend most of the execution time computing the samples.