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:
- make sure cost matters before spending lot of time on it. naive, easy right code, , profile instruments
- 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.
- 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
Post a Comment