The Wayback Machine - https://web.archive.org/web/20201201010507/https://github.com/microsoft/cpprestsdk/issues/249
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting utf16 to utf8 costs a lot time #249

Open
JasonYang-MSFT opened this issue Sep 26, 2016 · 3 comments
Open

Converting utf16 to utf8 costs a lot time #249

JasonYang-MSFT opened this issue Sep 26, 2016 · 3 comments

Comments

@JasonYang-MSFT
Copy link
Member

@JasonYang-MSFT JasonYang-MSFT commented Sep 26, 2016

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
Copy link

@grahamreeds grahamreeds commented Sep 26, 2016

This is minimally related to #72.

@JasonYang-MSFT
Copy link
Member Author

@JasonYang-MSFT JasonYang-MSFT commented Sep 27, 2016

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

@grahamreeds
Copy link

@grahamreeds grahamreeds commented Sep 27, 2016

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" [email protected] wrote:

#72 #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
#249 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEy9nEKOBCgHXQxbW7EoqhcItRXH9E_-ks5quJHngaJpZM4KGFDu
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.