From c489549b56861520b0d120034150f82a67faf953 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 4 Jun 2014 12:09:42 -0700 Subject: [PATCH] add benchmark of utf 32->8 encoding speed --- benchmark/test_utf_encoding.cpp | 100 ++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 benchmark/test_utf_encoding.cpp diff --git a/benchmark/test_utf_encoding.cpp b/benchmark/test_utf_encoding.cpp new file mode 100644 index 000000000..ad7fcc361 --- /dev/null +++ b/benchmark/test_utf_encoding.cpp @@ -0,0 +1,100 @@ +#include "bench_framework.hpp" +#include +#include +#include +#include + +class test : public benchmark::test_case +{ + std::string utf8_; +public: + test(mapnik::parameters const& params) + : test_case(params), + utf8_(u8"שלום") {} + bool validate() const + { + std::wstring_convert, char32_t> utf32conv; + std::u32string utf32 = utf32conv.from_bytes(utf8_); + if (utf32.size() != 4) return false; + if (utf32[0] != 0x5e9 && + utf32[1] != 0x5dc && + utf32[2] != 0x5d5 && + utf32[3] != 0x5dd) return false; + return true; + } + void operator()() const + { + std::u32string utf32; + std::wstring_convert, char32_t> utf32conv; + for (std::size_t i=0;i(utf8_); + if (utf32.size() != 4) return false; + if (utf32[0] != 0x5e9 && + utf32[1] != 0x5dc && + utf32[2] != 0x5d5 && + utf32[3] != 0x5dd) return false; + return true; + } + void operator()() const + { + std::u32string utf32; + for (std::size_t i=0;i(utf8_); + } + } +}; + +class test3 : public benchmark::test_case +{ + std::string utf8_; +public: + test3(mapnik::parameters const& params) + : test_case(params), + utf8_(u8"שלום") {} + bool validate() const + { + mapnik::transcoder tr_("utf-8"); + mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(),utf8_.size()); + //std::u32string utf32 = boost::locale::conv::utf_to_utf(utf8_); + if (utf32.length() != 4) return false; + if (utf32[0] != 0x5e9 && + utf32[1] != 0x5dc && + utf32[2] != 0x5d5 && + utf32[3] != 0x5dd) return false; + return true; + } + void operator()() const + { + mapnik::transcoder tr_("utf-8"); + mapnik::value_unicode_string utf32; + for (std::size_t i=0;i