From: Artyom <art...@ya...> - 2010-09-19 13:57:13
|
Hello, I've noticed that performance of icu::DateFormat is quite horrible: It takes about 200 microseconds to generate one date, in comparison to wcsftime that takes about 5 microseconds. I understand that icu::DateTime is much more powerful and supports different kinds of calendars, but still, it makes it quite hard to use in performance critical applications. Now more briefly: 200 microseconds: createDateTimeInstance and call format() 53 microseconds: clone() existing date time instance and call format() 18 microseconds: call format() for existing instance 4 microseconds: call wcsftime Now, on the paper there not a big difference between calling format() and wcsftime when I don't have to create any new instance of DateFormat, but in reality it is very problematic because I can't just cache such instance when working with multiple threads because it is not thread safe. Also any function that should use cached object and somehow access it. So only feasible and thread safe way do do such thing is to clone an existing instance that increases the time by an order of magnitude and still requires from me caching such instances for each case I need. So If I have a function like which should be reenterable and thread safe icu::UnicodeString getHumanReadableTimeStamp(); { std::auto_ptr<icu::DateTime> dt(icu::DateFormat::createDateTimeInstance()); icu::UnicodeString s; dt->format(1000.0 * std::time(0),s); return s; } It isn't possible to do it in less then 200 microseconds without using some static variables or in less then 53 microseconds without using thread local storage? Any suggestions or ways to improve the situation? Artyom |