Last active
September 19, 2019 17:06
-
-
Save zbraniecki/016f7bd35fc6e09aede997c5bc20222a to your computer and use it in GitHub Desktop.
Performance of ICU Locale parsing vs. unic-locale proposal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unicode/ures.h> | |
#include <unicode/putil.h> | |
#include <unicode/ustdio.h> | |
#include <unicode/locid.h> | |
#include <unicode/localebuilder.h> | |
#include <stdio.h> | |
#include <chrono> | |
#include <vector> | |
#include <cstring> | |
#ifndef _UASSERT | |
#define _UASSERT | |
#define ASSERT_OK(x) if(U_FAILURE(x)) { fprintf(stderr,"%s:%d: ICU Failure %s\n", __FILE__, __LINE__, u_errorName(x)); } | |
#endif | |
static void show(void); | |
void show(void) | |
{ | |
UErrorCode status = U_ZERO_ERROR; | |
{ | |
std::vector<std::string> ids; | |
ids.push_back("en-US"); | |
ids.push_back("en-GB"); | |
ids.push_back("es-AR"); | |
ids.push_back("it"); | |
ids.push_back("zh-Hans-CN"); | |
ids.push_back("de-AT"); | |
ids.push_back("pl"); | |
ids.push_back("fr-FR"); | |
ids.push_back("de-AT"); | |
ids.push_back("sr-Cyrl-SR"); | |
ids.push_back("nb-NO"); | |
ids.push_back("fr-FR"); | |
ids.push_back("mk"); | |
ids.push_back("uk"); | |
auto start = std::chrono::steady_clock::now(); | |
for (auto& id : ids) { | |
icu_64::Locale aLocale = icu_64::Locale(id.c_str()); | |
} | |
auto end = std::chrono::steady_clock::now(); | |
if(U_FAILURE(status)) { | |
printf("Can't open resource bundle. Error is %s\n", u_errorName(status)); | |
return; | |
} | |
auto diff = end - start; | |
auto diff_sec = std::chrono::duration_cast<std::chrono::nanoseconds>(diff); | |
printf("Create Locale from str time: %d ns\n", diff_sec); | |
} | |
} | |
int main() { | |
show(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On Thinkpad Carbon X1 gen 5, Arch Linux: | |
C++ code based on `language_identifier_from_str` benchmark in `unic-langid` crate. | |
Create Locale from str time: | |
C++ (gcc 8.3.): 68605 ns | |
Rust (Rust 1.34): 1268 ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment