]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/bench/utf8_checker/bench_utf8_checker.cpp
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #include <boost/beast/websocket/detail/utf8_checker.hpp>
11 #include <boost/beast/unit_test/suite.hpp>
15 #ifndef BEAST_USE_BOOST_LOCALE_BENCHMARK
16 #define BEAST_USE_BOOST_LOCALE_BENCHMARK 0
19 #if BEAST_USE_BOOST_LOCALE_BENCHMARK
20 #include <boost/locale.hpp>
26 class utf8_checker_test
: public beast::unit_test::suite
31 using size_type
= std::uint64_t;
37 std::chrono::system_clock
;
40 clock_type::time_point when_
;
47 : when_(clock_type::now())
54 return clock_type::now() - when_
;
58 template<class UInt
= std::size_t>
62 return static_cast<UInt
>(
63 std::uniform_int_distribution
<
64 std::size_t>{0, n
-1}(rng_
));
70 throughput(std::chrono::duration
<
71 double> const& elapsed
, size_type items
)
73 using namespace std::chrono
;
74 return static_cast<size_type
>(
75 1 / (elapsed
/items
).count());
84 s
.push_back(static_cast<char>(
90 checkBeast(std::string
const& s
)
92 beast::websocket::detail::check_utf8(
96 #if BEAST_USE_BOOST_LOCALE_BENCHMARK
98 checkLocale(std::string
const& s
)
100 using namespace boost::locale
;
102 auto const e
= s
.end();
105 auto cp
= utf::utf_traits
<char>::decode(p
, e
);
106 if(cp
== utf::illegal
)
113 typename
timer::clock_type::duration
124 auto const s
= corpus(32 * 1024 * 1024);
125 for(int i
= 0; i
< 5; ++ i
)
127 auto const elapsed
= test([&]{
134 log
<< "beast: " << throughput(elapsed
, s
.size()) << " char/s" << std::endl
;
136 #if BEAST_USE_BOOST_LOCALE_BENCHMARK
137 for(int i
= 0; i
< 5; ++ i
)
139 auto const elapsed
= test([&]{
146 log
<< "locale: " << throughput(elapsed
, s
.size()) << " char/s" << std::endl
;
153 BEAST_DEFINE_TESTSUITE(beast
,benchmarks
,utf8_checker
);