[cfe-dev] speed of clang++

Ivan Sorokin sorokin at rain.ifmo.ru
Sun Jan 24 15:34:19 PST 2010


Hi, all!

I've just write a test to check clang++ template instantiation speed.

Here it is:

#include <cstring>
#include <iostream>

template <typename parent, size_t N, bool v>
struct entry
{
   typedef parent parent_t;
   typedef entry<entry<parent, N, v>, N - 1, true> a;
   typedef entry<entry<parent, N, v>, N - 1, false> b;

   static const size_t value = a::value + b::value + 1;
};

template <typename parent, bool v>
struct entry<parent, 0, v>
{
   typedef parent parent_t;
   static const size_t value = 1;
};

int main()
{
   std::cout << entry<void, 12, false>::value << std::endl;
   return 0;
}


I've run both clang and g++:

ivan at ivan-desktop:~/d/llvm-build/Release/bin$ time ./clang++ 1.cpp

real	0m1.450s
user	0m1.300s
sys	0m0.130s
ivan at ivan-desktop:~/d/llvm-build/Release/bin$ ./a.out
8191
ivan at ivan-desktop:~/d/llvm-build/Release/bin$ time g++ 1.cpp

real	1m8.859s
user	1m8.520s
sys	0m0.170s
ivan at ivan-desktop:~/d/llvm-build/Release/bin$ ./a.out

8191

Clang is 46 times faster. Why clang is so fast, or why g++ is so slow?

Maybe I have bad g++? Or clang++ has incomplete template support, that 
is why it is so fast?

g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
clang revision 93461




More information about the cfe-dev mailing list