Boost logo

Boost Users :

From: SD (stefan.demharter_at_[hidden])
Date: 2008-07-10 03:45:11


On Mi, 2008-07-09 at 21:28 +0400, Vladimir Prus wrote:
> 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 <<EOF
> > // test.hpp
> > #ifndef TEST
> > #define TEST
> >
> > #include <string>
> >
> > int check(const std::string & test);
> >
> > #endif // TEST
> > EOF
> >
> > cat > test.cpp <<EOF
> > // test.cpp
> > #include "test.hpp"
> >
> > #include <boost/regex.hpp>
> >
> > 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 <<EOF
> > // main.cpp
> > #include "test.hpp"
> >
> > #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?

Yes, the runtimes vary only minimally.

Regards,
Stefan




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net