diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/test-unicode.cpp | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/src/test-unicode.cpp b/src/test-unicode.cpp index d638cbb..a30be70 100644 --- a/src/test-unicode.cpp +++ b/src/test-unicode.cpp @@ -1,11 +1,11 @@ #define BOOST_TEST_MODULE unicode_test +#include <boost/locale.hpp> #include <boost/test/included/unit_test.hpp> #include <boost/test/data/dataset.hpp> #include <boost/test/data/monomorphic.hpp> #include <boost/test/data/test_case.hpp> - -#include <boost/locale.hpp> +#include <boost/timer/timer.hpp> #include <array> #include <chrono> @@ -24,6 +24,7 @@ #include <unicode.h> using namespace std::chrono_literals; +using namespace std::string_literals; typedef std::tuple<std::basic_string<utf8_t>, std::basic_string<char16_t>, std::basic_string<char32_t>> types_collection_type; @@ -442,6 +443,27 @@ namespace { } } +class CPUTimer +{ +public: + CPUTimer(const std::string& name = "Timer"): mName(name), mWallTime0(std::chrono::steady_clock::now()) + { + } + + ~CPUTimer() + { + auto elapsed_cpu{mCPUTimer.elapsed()}; + std::cout << mName << ": " << std::chrono::duration<double>(std::chrono::steady_clock::now() - mWallTime0).count() << + "s (" << (double(elapsed_cpu.user + elapsed_cpu.system) / 1000000000) << + "s CPU)" << std::endl; + } + +private: + std::string mName; + std::chrono::time_point<std::chrono::steady_clock> mWallTime0; + boost::timer::cpu_timer mCPUTimer; +}; + template<typename From, typename ToTypesCollectionType, size_t index = 0> void test_random_valid(random_context& rc, size_t length, const std::string& description) { @@ -466,33 +488,24 @@ void test_random_valid(random_context& rc, size_t length, const std::string& des } { - auto t0{std::chrono::steady_clock::now()}; + CPUTimer timer("Performance test for converting "s + std::to_string(list.size()) + + " "s + description + + " from UTF-"s + std::to_string(sizeof(typename From::value_type) * 8) + + " to UTF-"s + std::to_string(sizeof(typename To::value_type) * 8)); for (const auto& i: list) To result{unicode::convert<typename unicode::Encoding<typename From::value_type>::Facet,typename unicode::Encoding<typename To::value_type>::Facet>(i)}; - std::cout << "Performance test for converting " << list.size() << - " " << description << - " from UTF-" << (sizeof(typename From::value_type) * 8) << - " to UTF-" << (sizeof(typename To::value_type) * 8) << ": " << - std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count() << "s" << - std::endl; } { - auto t0{std::chrono::steady_clock::now()}; + CPUTimer timer(" -> Compare to boost::locale::conv::utf_to_utf"); for (const auto& i: list) To result{boost::locale::conv::utf_to_utf<typename To::value_type, typename From::value_type>(i)}; - std::cout << " -> Compare to boost::locale::conv::utf_to_utf: " << - std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count() << "s" << - std::endl; } { - auto t0{std::chrono::steady_clock::now()}; + CPUTimer timer(" -> Compare to std::wstring_convert"); for (const auto& i: list) To result{std_convert<typename From::value_type, typename To::value_type>(i)}; - std::cout << " -> Compare to std::wstring_convert: " << - std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count() << "s" << - std::endl; } // iterate over remaining To types @@ -615,6 +628,10 @@ BOOST_AUTO_TEST_CASE(string_u8string) a = std::string{b.begin(), b.end()}; BOOST_CHECK(a == std::string{"\xc3\xa4"}); + + BOOST_CHECK(sizeof(size_t) == 4 || sizeof(size_t) == 8); + + std::cout << "Detected CPU Accu size: " << (sizeof(size_t) * 8) << std::endl; } // check environment: demonstrate how boost convert u8->u8 throws exception on invalid input |