Re: years:months:days:hours:minutes:seconds:sinceDate: really slow!
Re: years:months:days:hours:minutes:seconds:sinceDate: really slow!
- Subject: Re: years:months:days:hours:minutes:seconds:sinceDate: really slow!
- From: Malte Tancred <email@hidden>
- Date: Fri, 23 Aug 2002 12:11:36 +0200
On thursday, august 22, 2002, at 12:51 , David Sinclair wrote:
On further investigation I narrowed it down to the date calculations
within that method; passing zeroes for the years:months:days: parts
didn't exhibit the slowness, but passing non-zeros for any of those
did. There was no noticeable performance hit with the time parameters.
I would guess that that is due to heavy-duty calculations to cope with
leap years and other factors.
Are you sure? I find it hard to believe.
Take a look at this:
[prune:~/Dev/temp/slowdate] malte% cat slowdate.m
#import <Foundation/Foundation.h>
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDate *start, *end;
NSCalendarDate *then, *howMany;
int i;
then = [NSCalendarDate dateWithYear:1975 month:04 day:23
hour:19 minute:32 second:0 timeZone:nil];
start = [NSDate date];
for (i=0; i < 10000; i++) {
int years, months, days;
int hours, minutes, seconds;
howMany = [NSCalendarDate date];
[howMany years:&years months:&months days:&days
hours:&hours minutes:&minutes seconds:&seconds
sinceDate:then];
}
end = [NSDate date];
NSLog(@"Time elapsed: %f", [end timeIntervalSinceDate:start]);
[pool release];
exit(0);
return 0;
}
[prune:~/Dev/temp/slowdate] malte% cc -o slowdate slowdate.m -framework
Foundation
[prune:~/Dev/temp/slowdate] malte%
./slowdate 2002-08-23 12:06:52.467
slowdate[846] Time elapsed: 1.488464
I'm on a PowerBook G4 500 MHz. Heavy duty? :-)
Regards,
Malte
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.