On Thu, Jan 15, 2009 at 2:16 PM, Jens Bauer <jensba...@christian.net> 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 (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