
SD wrote:
Hi,
i've encountered a significant performance difference with boost_regex between linking first to it and linking last to it. I guess it is not a issue specific to boost_regex, but maybe someone can clarify that.
I have created the following test files and tested with gcc-4.1 and gcc-4.3 on 64-bit linux and gcc-4.1.2 on 32-bit linux. The results for 64bit are further down, but the results for 32-bit are very similar.
****
# set your boost_extension (i.e. -mt) # export BOOST_EXT=-mt
cat > test.hpp <
#include <string>
int check(const std::string & test);
#endif // TEST EOF
cat > test.cpp <
#include
int check(const std::string & test) { int result = 0; static boost::regex match("a*b*c*d*e*f*g*h*i*j*k*a*b*c*d*e*f*g*h*i*a*b*c*d*e*f*g*h*i*j*"); for (int i = 0; i < 1000; ++i) { result += boost::regex_match(test, match); } return result; } EOF
cat > main.cpp <
#include <iostream>
int main() { std::cout << check("abcdaaaaaaaaaabcdefgaaaaaaaaaaabbbbbbbbbddeef") << std::endl; } EOF
# Create libtest.so g++ -shared -fPIC test.cpp -o libtest.so # link boost_regex before libtest.so g++ main.cpp -lboost_regex${BOOST_EXT} -ltest -L${PWD} -o main_fast # link boost_regex after libtest.so g++ main.cpp -ltest -lboost_regex${BOOST_EXT} -L${PWD} -o main_slow
time env LD_LIBRARY_PATH=${PWD} ./main_slow # real 0m0.753s, user 0m0.746s, sys 0m0.004s time env LD_LIBRARY_PATH=${PWD} ./main_fast # real 0m0.104s, user 0m0.103s, sys 0m0.002s
As the results show the order which libs are being linked to the program has significant performance impacts on execution time: main_fast is about 7 times faster than main_slow. .... I would appreciate if someone could explain these surprising results.
Before we go on guessing what could cause this -- do you get the same timings on successive runs of any given executable? - Volodya