2009年11月1日 星期日

The effect of pre compiled header in gcc

每次使用C++ , 為了擺脫漫長無盡的 compilation time. 我不得不看一下 precompiled header..

[pre.h]
#include<tr1/unordered_map>
#include<tr1/unordered_set>
#include<tr1/regex>
#include"iostream"
#include"algorithm"
#include"string"
#include"vector"
#include"fstream"



[main.cpp]
#include"pre.h"
using namespace std;
using namespace tr1;
int main(){
vector<int> v;
string s = "tim";
unordered_map<int,int> um;
cout<<"yes"<<endl;
return 0;
}




只要g++ pre.h 就可以產出 pre.h.gch
以後gcc 會優先使用 pre.h.gch.

[Result of benchmark by time:]

Without precompiled header.
real 0m0.370s
user 0m0.336s
sys 0m0.036s


With precompiled header.
real 0m0.120s
user 0m0.088s
sys 0m0.036s

看來可以省一半以上的時間!  
以後在更大的project 再來測測看

沒有留言: