Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards


Boost.Convert Overhead

Boost.Convert framework adds an additional layer of indirection and some Boost.Convert converters are wrappers around actual conversion facilities such as boost::lexical_cast, boost::spirit, etc. Consequently, there might be reasonable concerns with regard to the performance overhead introduced by the framework as opposed to deploying conversion facilities directly.

To test that code has been borrowed and adapted from the Spirit.Qi performance/optimization framework (see $BOOST_ROOT/libs/spirit/workbench/qi/int_parser.cpp). The tests were

  1. compiled using gcc-4.6.3 and gcc-4.8.2;
  2. with optimization: g++ -O3 test/performance_spirit.cpp -Iinclude -I../boost_1_56_0 -lrt;
  3. on 64-bit Ubuntu 12.04 and 32-bit Ubuntu 14.04;
  4. run against the input of randomly generated 18 numeric strings (9 positive and 9 negative numbers with the number of digits from 1 to 9);
  5. run for
    • boost::lexical_cast and boost::lexical_cast-based converter;
    • boost::spirit::qi::parse and boost::spirit::qi::parse-based converter.

The purpose of the test was to deploy the same functionality directly and as part of the Boost.Convert framework. Results are shown below for several consecutive runs:

gcc-4.6.3 (64-bit)
raw_lxcast_str_to_int_test: 1.0504170070 [s]
cnv_lxcast_str_to_int_test: 1.0610595810 [s] (1% slower than raw above)
raw_spirit_str_to_int_test: 0.2845369110 [s]
cnv_spirit_str_to_int_test: 0.2834834560 [s] (1% faster than raw above)

raw_lxcast_str_to_int_test: 1.0770350390 [s] (2% slower than prev. run)
cnv_lxcast_str_to_int_test: 1.0607665160 [s] (1% faster than raw above)
raw_spirit_str_to_int_test: 0.2792295470 [s] (2% faster than prev. run)
cnv_spirit_str_to_int_test: 0.2827574570 [s] (1% slower than raw above)

gcc-4.8.2 (32-bit)
raw_lxcast_str_to_int_test: 8.5153330600 [s]
cnv_lxcast_str_to_int_test: 8.6989499850 [s] (2% slower than raw above)
raw_spirit_str_to_int_test: 2.4197476510 [s]
cnv_spirit_str_to_int_test: 2.4594171510 [s] (2% slower than raw above)

raw_lxcast_str_to_int_test: 8.4136546980 [s] (1% faster than prev. run)
cnv_lxcast_str_to_int_test: 8.5322524600 [s] (1% slower than raw above)
raw_spirit_str_to_int_test: 2.3842388060 [s] (1% faster than prev. run)
cnv_spirit_str_to_int_test: 2.3812094400 [s] (0% faster than raw above)

The results for consecutive runs varied with deviations of around 2%. Under 2% was also the deviation of the "cnv" code compared to the "raw" code. That indicates that the Boost.Convert framework had no detectable running overhead with the tested compilers, hardware and deployment scenarios. The results might be different on other platforms.