0

I'm porting some application from wchar_t for C strings to char16_t offered by C++11.

Although I have an issue. The only library I found that can handle snprintf for char16_t types is ICU with their UChar types.

The performance of u_snprintf_u (equivalent to swprintf/snprintf, but taking Uchar as arguments) is abismal.

Some testing leads to u_snprintf_u being 25x slower than snprintf.

Example of what I get on valgrind :

callgrind

As you can see, the underlying code is doing too much work and instanciating internal objects that I don't want.

Edit : The data I'm working with doesn't need to be interpreted by the underlying ICU code. It's ascii oriented. I didn't find any way to tell ICU to not try to apply locales and such on such function calls.

RitonLaJoie
  • 211
  • 3
  • 5
  • Make sure you are compiling with optimizations enabled. Not your core problem, I know, but it's just Step 1 in making things "not slow". :) – Jesper Juhl Dec 20 '18 at 19:58
  • By "ascii oriented" do you mean that it only contains ascii code points? If so you could probably speed up by naively converting the format to ascii, calling printf, and expanding the output – M.M Dec 20 '18 at 23:51
  • Is this for Windows or for another OS? – Peter Torr - MSFT Feb 11 '19 at 04:30

0 Answers0