Many thanks for all the suggestions, much appreciated.

Although -timeIntervalSinceReferenceDate: may indeed be a workable solution as 
the XML is our own format so I could make this choice, for now I think I'd like 
to retain a human-readable date. Mike's suggestion of creating one 
NSDateFormatter and passing all of the dates through that (as opposed to 
relying on the standard methods which most likely create a formatter 
per-instance) boosted performance significantly, so I'm going to see if I can 
squeeze more speed elsewhere and go with that.

Thanks again!
All the best,
Keith

--- On Mon, 1/25/10, Mike Abdullah <cocoa...@mikeabdullah.net> wrote:

> From: Mike Abdullah <cocoa...@mikeabdullah.net>
> Subject: Re: Fastest way to convert an NSDate into an NSString
> To: "Keith Blount" <keithblo...@yahoo.com>
> Cc: cocoa-dev@lists.apple.com
> Date: Monday, January 25, 2010, 8:33 PM
> This approach is probably creating a
> new NSDateFormatter for each date processed. What if you
> create your own formatter and use that for all dates?
> 
> 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.)
> > 
> > Many thanks and all the best,
> > Keith
> > 
> > 
> > 
> > _______________________________________________
> > 
> > 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/cocoadev%40mikeabdullah.net
> > 
> > This email sent to cocoa...@mikeabdullah.net
> 
> 


      
_______________________________________________

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