Jason Merrill пишет:
On 09/08/2010 07:40 AM, Ilya Murav'jov wrote:
Dave Abrahams пишет:
G++4.5 implements O(1) template lookup, which could have a
significant
effect for Boost users.
Thanks for the info. I've built gcc-4.5.1 myself and got not very
comforting results: g++4.2 is still 'unbeaten', g++4.5 is 15% slower.
Hmm, that's disappointing. I grabbed the source file you mentioned, but
it seems to depend on other headers from your project; if you send me a
preprocessed file I'll try to take a look at what's slowing it down
sometime soon.
Jason
After some experiments I've done a clear example. It shows that
boost::lambda::bind() invocation cost 0.1 sec. Here is the code:
//////////////////// begin ////////////////////////
#include // boost::lambda::bind
#include // boost::function
typedef boost::function TestFunctor;
template<int value>
struct TestStruct
{
};
#define IMPL_DEF_(Idx, Type) void Impl ## Idx(Type) {} \
void TestImpl ## Idx() \
{ \
TestFunctor fnr; \
fnr = boost::lambda::bind(&Impl ## Idx, Type()); \
} \
/**/
#define IMPL_DEF(Idx) IMPL_DEF_(Idx, TestStruct<Idx>)
#define IMPL_DEF_10_(Idx) \
IMPL_DEF(Idx ## 0) \
IMPL_DEF(Idx ## 1) \
IMPL_DEF(Idx ## 2) \
IMPL_DEF(Idx ## 3) \
IMPL_DEF(Idx ## 4) \
IMPL_DEF(Idx ## 5) \
IMPL_DEF(Idx ## 6) \
IMPL_DEF(Idx ## 7) \
IMPL_DEF(Idx ## 8) \
IMPL_DEF(Idx ## 9) \
/**/
#define IMPL_DEF_10(Idx) IMPL_DEF_10_(Idx)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
IMPL_DEF_10(__LINE__)
//////////////////// end ////////////////////////
It does 100 invocations of boost::lambda::bind() with various types.
Benchmarks with "-c -g -O0 -pipe", Boost 1.44:
G++ 4.2.4: 14.75 sec
G++ 4.5.1: 09.57 sec
P.S. It shows that g++4.5 is quicker, though. :) Later I try to do
examples with other constructs (BOOST_FOREACH, Boost.Range, B.Function)
to find out where g++4.2 is better.
P.S.S. I suggest to make comparison among varios compilers (i.e., clang,
msvc, icc) with this test. It is interesting to see the quickest (don't
forget to include your CPU).
Regards,
Ilya