Boost logo

Boost Users :

From: stefan.demharter_at_[hidden]
Date: 2008-07-10 12:06:10


On Do, 2008-07-10 at 19:08 +0400, Vladimir Prus wrote:
> SD wrote:
>
> >> > # 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.
>
> Does running ldd on both binaries report that the same boost_regexp binary
> is being linked to? I don't see why different ones would be linked to, but
> still.
>
> If this theory is wrong, can you create a self-contained archive with all
> the necessary files, and send it, so that I (and others) can try to reproduce.
> This sounds truly bizarre.
>
> - Volodya

$ LD_LIBRARY_PATH=./ ldd ./main_slow
        linux-vdso.so.1 => (0x00007fff1bbff000)
        libtest.so => ./libtest.so (0x00007ffc136fd000)
        libboost_regex.so => /usr/lib/libboost_regex.so (0x00007ffc1346b000)
        libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.1/libstdc++.so.6
(0x00007ffc13168000)
        libm.so.6 => /lib/libm.so.6 (0x00007ffc12ee8000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007ffc12cd2000)
        libc.so.6 => /lib/libc.so.6 (0x00007ffc12992000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ffc13914000)

$ LD_LIBRARY_PATH=./ ldd ./main_fast
        linux-vdso.so.1 => (0x00007ffffe9fe000)
        libboost_regex.so => /usr/lib/libboost_regex.so (0x00007f88f636f000)
        libtest.so => ./libtest.so (0x00007f88f6158000)
        libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.1/libstdc++.so.6
(0x00007f88f5e55000)
        libm.so.6 => /lib/libm.so.6 (0x00007f88f5bd5000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f88f59bf000)
        libc.so.6 => /lib/libc.so.6 (0x00007f88f567f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f88f6601000)

As you can see, the only difference seems to be the position of
libtest.so and libboost_regex.so, whereas in the fast version
libboost_regex is linked in first.

I've attached 4 files. You can run ./runtest.sh in the directory to run
the tests.

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