microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
8.01k stars 1.66k forks source link

Converting utf16 to utf8 costs a lot time #249

Open JasonYang-MSFT opened 8 years ago

JasonYang-MSFT commented 8 years ago

As mentioned in the title, utf16_to_utf8 costs a lot time. For 1 MB utf16 string, it would costs 5 seconds on Win10 with E5-1620 machine. And the costs increased by linear, 11 seconds for 2 MB, 22 seconds for 4 MB e.g.

Here is the sample code:

#include "stdafx.h"
#include "cpprest/asyncrt_utils.h"

int main()
{
    int length = 1 * 1024 * 1024;
    utility::datetime start = utility::datetime::utc_now();
    utility::string_t text(length, _XPLATSTR('C'));
    auto content = utility::conversions::utf16_to_utf8(text);
    utility::datetime end = utility::datetime::utc_now();
    ucout << "String Length: " << length << std::endl;
    ucout << "Time Cost: " << end - start << " second(s)" << std::endl;
    return 0;
}

Is there a better way to do the conversion? Could the performance of utf16_to_utf8 be improved?

grahamreeds commented 8 years ago

This is minimally related to #72.

JasonYang-MSFT commented 8 years ago

72 was discussing about to avoid such kind of conversion. But I am more concerned about the conversion performance here.

grahamreeds commented 8 years ago

The fastest code is code that isn't ran, and I did say it was kind of related. Fixes in this area would help both.

Sent from my Nexus 6P

On 27 Sep 2016 04:47, "Jason Yang" notifications@github.com wrote:

72 https://github.com/Microsoft/cpprestsdk/issues/72 was discussing

about to avoid such kind of conversion. But I am more concerned about the conversion performance here.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/cpprestsdk/issues/249#issuecomment-249759225, or mute the thread https://github.com/notifications/unsubscribe-auth/AEy9nEKOBCgHXQxbW7EoqhcItRXH9E_-ks5quJHngaJpZM4KGFDu .