• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ObjC in time-critical parts of the code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC in time-critical parts of the code


  • Subject: Re: ObjC in time-critical parts of the code
  • From: Shawn Erickson <email@hidden>
  • Date: Thu, 15 Jan 2009 17:48:53 -0800

On Thu, Jan 15, 2009 at 2:16 PM, Jens Bauer <email@hidden> wrote:

> - (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".

#include <Foundation/Foundation.h>
#include <CoreServices/CoreServices.h>

@interface MyObject : NSObject
@end

@implementation MyObject

- (void) renderObject
{
}

@end

int main(int argc, char* argv[]) {
    MyObject* obj = [[MyObject alloc] init];

    int i;
    UnsignedWide us;
    uint64_t startTime;
    uint64_t endTime;

    Microseconds(&us);
    startTime = UnsignedWideToUInt64(us);
    [obj renderObject];
    Microseconds(&us);
    endTime = UnsignedWideToUInt64(us);
    NSLog(@"time using Microseconds average for 1 send: %llu ns",
(endTime - startTime) * 1000ULL );

    startTime = UnsignedWideToUInt64(UpTime());
    [obj renderObject];
    endTime = UnsignedWideToUInt64(UpTime());
    NSLog(@"time using UpTime average for 1 send: %llu ns", (endTime -
startTime) );

    Microseconds(&us);
    startTime = UnsignedWideToUInt64(us);
    for (i = 0; i < 10000; i++) {
        [obj renderObject];
    }
    Microseconds(&us);
    endTime = UnsignedWideToUInt64(us);
    NSLog(@"time using Microseconds average for 10000 sends: %llu ns",
(endTime - startTime) / 10ULL );

    startTime = UnsignedWideToUInt64(UpTime());
    for (i = 0; i < 10000; i++) {
        [obj renderObject];
    }
    endTime = UnsignedWideToUInt64(UpTime());
    NSLog(@"time using UpTime average for 10000 sends: %llu ns",
(endTime - startTime) / 10000ULL );
}

[0:560] > gcc -framework Foundation -framework CoreServices Test.m; ./a.out
2009-01-15 17:45:57.233 a.out[42285:10b] time using Microseconds
average for 1 send: 22000 ns
2009-01-15 17:45:57.235 a.out[42285:10b] time using UpTime average for
1 send: 673 ns
2009-01-15 17:45:57.236 a.out[42285:10b] time using Microseconds
average for 10000 sends: 7 ns
2009-01-15 17:45:57.237 a.out[42285:10b] time using UpTime average for
10000 sends: 7 ns

-Shawn
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Re: Filtering NSPopUpButtonCell when clicking on it (From: Keary Suska <email@hidden>)
 >Fwd: Filtering NSPopUpButtonCell when clicking on it (From: Kubernan <email@hidden>)
 >ObjC in time-critical parts of the code (From: Jens Bauer <email@hidden>)

  • Prev by Date: Re: Nib memory management under Garbage Collection
  • Next by Date: detecting touches not from a view/window on iphone
  • Previous by thread: Re: ObjC in time-critical parts of the code
  • Next by thread: Re: ObjC in time-critical parts of the code
  • Index(es):
    • Date
    • Thread