Boost logo

Boost :

Subject: Re: [boost] [beast] Formal review
From: Artyom Beilis (artyom.beilis_at_[hidden])
Date: 2017-07-10 21:06:20


Interesting...

How did you get these numbers...
My small benchmark (see below)

Gives

For: https://en.wikipedia.org/wiki/War_and_Peace
Beast 0.0555949ms
Locale 0.110325ms

For: https://he.wikipedia.org/wiki/%D7%9E%D7%9C%D7%97%D7%9E%D7%94_%D7%95%D7%A9%D7%9C%D7%95%D7%9D
Beast 0.0542079ms
Locale 0.0772768ms

For: https://zh.wikipedia.org/wiki/%E6%88%B0%E7%88%AD%E8%88%87%E5%92%8C%E5%B9%B3
Beast 0.0849873ms
Locale 0.0930336ms

using gcc 5.4.0 Ubuntu 64 bit.

I mean Beast is somewhat faster but by no means by the magnitude you show
Have you run your benchmark using release mode?

It looks for me you are running into premature optimization.

Artyom

----------------------------------
#include <beast/websocket/detail/utf8_checker.hpp>
#include <boost/locale.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <chrono>

bool locale_test(char const *msg,size_t len)
{
       char const *e = msg + len;
       while(msg!=e) {
               using namespace boost::locale;
               auto cp = utf::utf_traits<char>::decode(msg,e);
               if(cp == utf::illegal || cp==utf::incomplete)
                       return false;
       }
       return true;
}

int main()
{

       std::ifstream tmp("/tmp/index.html");
       std::stringstream ss;
       ss << tmp.rdbuf();
       std::string sample = ss.str();

       using beast::websocket::detail::check_utf8;

       int factor = 10;
       {
               auto start = std::chrono::high_resolution_clock::now();
               for(int i=0;i<factor*1000;i++) {
                       bool v1 = check_utf8(sample.c_str(),sample.size());
               }
               auto end = std::chrono::high_resolution_clock::now();
               double time =
std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>
> >(end-start).count() / factor;
               std::cout << "Beast " << time << "ms" << std::endl;
       }
       {
               auto start = std::chrono::high_resolution_clock::now();
               for(int i=0;i<factor*1000;i++) {
                       bool v2 = locale_test(sample.c_str(),sample.size());
               }
               auto end = std::chrono::high_resolution_clock::now();
               double time =
std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>
> >(end-start).count() / factor;
               std::cout << "Locale " << time << "ms" << std::endl;
       }

}

>
> Benchmark results:
>
> beast.benchmarks.utf8_checker
> beast: 2,016,637,738 char/s
> beast: 1,921,062,599 char/s
> beast: 1,939,159,018 char/s
> locale: 3,053,539 char/s
> locale: 2,989,265 char/s
> locale: 3,060,962 char/s
> Longest suite times:
> 17.8s beast.benchmarks.utf8_checker
> 17.8s, 1 suite, 1 case, 1 test total, 0 failures
> The program '[75300] benchmarks.exe' has exited with code 0 (0x0).
>
> Code:
> <https://github.com/vinniefalco/Beast/commit/3df7de8ce2e8f797722118b9d751266241a8266e>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk