| CXX | Templates | Templates with Forward Decls | 
|---|---|---|
| clang 4.0 | 30s | 12s compile + 16s link | 
| g++ 6.2 | 48s | 14s compile + 12s link | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // ... | |
| // Vector class above | |
| // Forward declaration of common sizes | |
| extern template class Vector<16>; | |
| extern template class Vector<32>; | |
| extern template class Vector<64>; | |
| extern template class Vector<128>; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <vector.hpp> | |
| // Instantiation of common sizes | |
| template class Vector<16>; | |
| template class Vector<32>; | |
| template class Vector<64>; | |
| template class Vector<128>; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Vector<16> is in another binary | |
| extern template class Vector<16>; | 
| CXX | Macros | Preprocessed Macros | Templates | 
|---|---|---|---|
| clang 4.0 | 40s | 37s | 30s | 
| g++ 6.2 | 61s | 66s | 48s | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #define CREATE_VECTOR(D) \ | |
| struct Vector_##D {\ | |
| static constexpr int N = D;\ | |
| int data[N];\ | |
| \ | |
| Vector_##D (Vector_##D const& v) {\ | |
| for(int i=0; i<N ; ++i) {\ | |
| data[i] = v[i];\ | |
| }\ | |
| }\ | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | template<int D> | |
| struct Vector { | |
| static constexpr unsigned N = D; | |
| int data[N]; | |
| Vector(Vector<D> const& v) { | |
| for (int i = 0; i < N; ++i) { | |
| data[i] = v[i]; | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Create a vector of 10 elements, all initialized to 0 | |
| auto v = Vector<10>(0); | |
| // Set the 1st element to 7 | |
| v[0] = 7; | |
| // Set the 9th element to 3 | |
| v[8] = 3; | |
| // Print the sum of all elements | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import com.google.common.base.Charsets; | |
| import com.google.common.io.MoreFiles; | |
| import com.google.common.io.ByteSink; | |
| import java.nio.file.Path; | |
| public final class GuavaFileUtils { | |
| private GuavaFileUtils() { | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | constexpr unsigned fibonacci(const unsigned x) { | |
| return x <= 1 ? | |
| 1 : | |
| fibonacci(x - 1) + fibonacci(x - 2); | |
| } | |
| int main() { | |
| return fibonacci(5); | |
| } |