We are using the following standard boost spirit code to convert a series of string containing list of floating point numbers to float arrays. The input data is quite huge(running into many GBs of text.) Therefore performance is critical. We use the code in multithreaded enviroment. Recently we noticed significant performance degradation in this API in two versions of this code. The compiler version, flags and the boost version is same across the two versions. The only relevant change is using STL vector as the output container instead of a simple implementation of array container. I am not sure if the degradation in run time is due to change in container or something else(as degradation is around 50 percent which can not be explained by use of STL vector.). We use Sun collector for profiling and it shows significant increase in CPU time in case of multithreaded testcase. What can be the reason other than the change in container type for degradation , given that boost verssion is same and compiler/compiler flags are also same. Any suggestions are welcome.
Thanks.
#define BOOST_SPIRIT_THREADSAFE
#include <boost/config/warning_disable.hpp>
#include "boost/spirit/include/qi.hpp"
#include "boost/spirit/include/phoenix_core.hpp"
#include "boost/spirit/include/phoenix_operator.hpp"
#include "boost/spirit/include/phoenix_stl.hpp"
#include <vector>
bool parse_numbers(const char* first, const char* last, std::vector<float> &v)
{
using qi::phrase_parse;
using qi::_1;
using ascii::space;
using phoenix::push_back;
using qi::double_;
bool r = phrase_parse(first, last,
(
double_[push_back(phoenix::ref(v), _1)]
>> *((',' >> qi::double_[push_back(phoenix::ref(v), _1)]) |
(qi::double_[push_back(phoenix::ref(v), _1)]))
)
,
space);
return r;
}
int main()
{
const char *input1 = "3.4 567, 89, 90 91";
const char *input2 = "3.4, 567, 89, 90, 91";
const char *input3 = "3.4 567 89, 90 91";
std::vector<float myVec;
parse_numbers(input1, input1 + strlen(input1), myVec);
myVec.clear();
parse_numbers(input2, input2 + strlen(input2), myVec);
myVec.clear();
parse_numbers(input3, input3 + strlen(input3), myVec);
}