Re: Fastest way to convert an NSDate into an NSString
Re: Fastest way to convert an NSDate into an NSString
- Subject: Re: Fastest way to convert an NSDate into an NSString
- From: "email@hidden" <email@hidden>
- Date: Mon, 25 Jan 2010 20:31:38 +0000
On 25 Jan 2010, at 20:23, Keith Blount wrote:
> Hello,
>
> I am in the process of converting the data format for my application from one that just uses the NSKeyedArchiver methods to archive my objects to a file on disk to using the NSXML classes to generate a custom XML file (I need to do this for compatibility purposes). My main data object is essentially a (potentially very long) list (or rather tree) of items, each of which have two or three dates associated with them (among other things).
>
> Having completed the initial conversion process, it turns out that currently my XML-writing methods (using NSXMLElement, NSXMLDocument etc) are much, much slower than using NSKeyedArchiver. Using Sample, it turns out that a lot of the time is spent converting the NSDates for each of the items in my list to string objects. I have tried this using two different methods:
>
> NSDate *someDate = ...
>
> [xmlElement addAttribute:[NSXMLNode attributeWithName:"SomeDate" stringValue:[someDate descriptionWithLocale:nil]]];
>
> and
>
> NSXMLNode *attribute = [[NSXMLNode alloc] initWithKind:NSXMLAttributeKind];
> [attribute setName:@"SomeDate"];
> [attribute setObjectValue:someDate]
> [xmlElement addAttribute:attribute];
> [attribute release];
>
> But either way suffers the same performance hit. So, my question is, does anyone know of a much faster and more efficient way of converting NSDates to NSStrings? (A possible solution would be to change my data model to store these dates as strings internally so that the conversion is already done when they come to be written to file, but I was hoping for a more elegant solution.)
>
I don't know if this will help in your case.
I previously noted the performance hit that occurred with NSDate but it seemed to occur largely as a result of instantiation.
I reused a single static NSDate instance and saw improvements.
Regards
Jonathan Mitchell
Developer
http://www.mugginsoft.com
> Many thanks and all the best,
> Keith
>
>
>
> _______________________________________________
>
> 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
_______________________________________________
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