ios - NSDateFormatter init vs copy performance -


my ios application requires heavy use of nsdateformatter, know creating instance of nsdateformatter expensive, creating few singleton instances fine, need use lot of date formats , cannot create instance of these formats,

what doing creating singleton nsdateformatter common settings timezone , locale, , whenever want clone nsdateformatter , make change that,

my question

does copy better clone?

what best practice handle many date formats ?

unfortunately, expense of date formatter setup incurred first time use after either creating or setting properties of it. won't able avoid cost @ least once each configuration of formatter use.

i have few suggestions:

  1. make sure cost matters before spending lot of time on it. naive, easy right code, , profile instruments
  2. look @ usage patterns. use few formats far more rest? consider caching those. use few @ time, few different ones, , on? consider caching small number of used formatters can exploit pattern.
  3. in worst case scenario (formatter performance matter, , there's no pattern how use them), consider writing class manage cache of formatters , clear them when memory pressure warning. way can try best performance possible when not running low on ram, , free ram when need it.

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -