billymeltdown / nsdate-helper

A category to extend Cocoa's NSDate class with some convenience functions.
http://www.zetetic.net/blog/
456 stars 107 forks source link

Performance improvements #4

Closed jkubicek closed 13 years ago

jkubicek commented 13 years ago

I'm performing about 200+ date formats at the same time. Moving the calendar and dateFormatter into static variables and initializing them just once improved performance by a significant amount.

billymeltdown commented 13 years ago

Nice work, sir. Just tried it out on Codebook, looks good, just merged and pushed your pull request. Thanks!

billymeltdown commented 10 years ago

Well, this may not still be thread-safe, however I've updated the category on the develop branch to lazily load a single, static NSCalendar and NSDateFormatter for use, dramatically increasing performance. Uses dispatch_once() to avoid doing it over and over again. Appears to work, you can see the commit here:

https://github.com/billymeltdown/nsdate-helper/commit/eff44b2a9a6e07a53a2db981612302e8f0cc062b

billymeltdown commented 10 years ago

Circling back here: I just pushed to master what I've been using for a little bit on develop branch—using dispatch_once to initialize static variables for NSDateCalendar and NSDateFormatter.