Le 15 janv. 09 à 23:16, Jens Bauer a écrit :

Hi all,

I just want to let you know that I discovered I did a terrible mistake today. In other words: you don't have to learn from your own mistakes, if you can learn from mine. =)

I investigated this, because my rendering was choppy.

The code...

- (void)renderObject
{
}

- (void)renderAll
{
        UnsignedWide    us;
        double                  time;

        Microseconds(&us);
        time = ((double) us.hi) * 65536.0 * 65536.0 + ((double) us.lo);
        [self renderObject];

        Microseconds(&us);
time = ((double) us.hi) * 65536.0 * 65536.0 + ((double) us.lo) - time;

        NSLog(@"time:%.3fms", time * 0.001);
}

..often used around 3ms for the empty method "-renderObject".
It gave me the terrible result of up to 21ms spent in the empty method!


-So I'd like to let you know that it's sometimes good to think "do I really need this method?" I will be rewriting around 8 of my large files for doing some rendering, so they will be using C-routines instead of ObjC methods, since I'm using them in a real-time environment.

My guess is that the message dispatcher probably needs to do something else than servicing *my* application, so I believe it's the nature of the environment, not a bug.


Got this with Test.m:

elapsed: 7257238014 ns (7.257238 ns per call)

--------- Test.m ---------
#import <Foundation/Foundation.h>
#include <mach/mach_time.h>

@interface Foo : NSObject {

}

- (void)nop;

@end

@implementation Foo

- (void)nop {}

@end


int main(int argc, char **argv) {
  Foo *foo = [[Foo alloc] init];
  uint64_t delta = mach_absolute_time();
  for (NSUInteger idx = 0; idx < 1000000000; idx++) {
    [foo nop];
  }
  delta = mach_absolute_time() - delta;
  [foo release];

  /* convert to nano */
  mach_timebase_info_data_t sTimebaseInfo;
  mach_timebase_info(&sTimebaseInfo);

  delta = delta * sTimebaseInfo.numer / sTimebaseInfo.denom;
fprintf(stderr, "elapsed: %qu ns (%f ns per call)\n", delta, delta / 1000000000.0);

        return 0;
}
------------------------------------


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to