Boost logo

Boost :

Subject: Re: [boost] [convert] Performance
From: Vladimir Batov (vb.mail.247_at_[hidden])
Date: 2014-06-11 02:58:50


Joel de Guzman wrote
> Benchmarks are a black art. See how we do our performance tests in Spirit:
> You can use our benchmark facility where all the black art is contained:
> ...
> Joel de Guzman

Thank you for the pointers. I've

1) #included "qi/int_parser.cpp";
2) made spirit_new_test from spirit_int_test;
3) added boost::convert()-based test;
4) compiled with gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 with "g++ -O2 -std=c++11
5) got the following results:

atoi_test: 2.2135431510 [s] {checksum: 730759d}
strtol_test: 2.1688206260 [s] {checksum: 730759d}
spirit_int_test: 0.5207926250 [s] {checksum: 730759d}
spirit_new_test: 0.5803735980 [s] {checksum: 730759d}
cnv_test: 0.6161884860 [s] {checksum: 730759d}

struct spirit_new_test : test::base
    static int parse(std::string const& str)
        std::string::const_iterator beg = str.begin();
        std::string::const_iterator end = str.end();
        int n;

        if (boost::spirit::qi::parse(beg, end, boost::spirit::qi::int_, n))
            if (beg == end)
                return n;

        return (BOOST_ASSERT(0), 0);
    void benchmark()
        for (int i = 0; i < 9; ++i)
            this->val += parse(numbers[i]);

struct cnv_test : test::base
    void benchmark()
        for (int i = 0; i < 9; ++i)
            this->val += boost::convert<int>(numbers[i],

1. The changes in spirit_new_test compared to the original spirit_int_test
were additional conversion validity checks and the std::string... the same
way boost::cnv::spirit works. That slowed spirit_new_test some 11% compared
to spirit_int_test. Though raw conversion speed is important
(spirit_int_test) I do not expect it deployed like that (with no checks) in
a realistic setting.

2. boost::cnv::spirit implements the same process-flow as spirit_new_test
and boost::cnv::spirit was consistently 6% slower compared to raw spirit
conversion deployment with the same functionality (spirit_new_test).

Thank you, Joel, for sharing your performance testing framework.

View this message in context:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at