我正在寻找针对较短的编译时间进行优化的 STL 变体(如果它不具备所有功能也没关系)——我对延迟的较长编译时间感到困扰我的编译-调试-编辑周期。
我主要对 STL 的容器感兴趣:vector/map,而不是算法。
谢谢!
最佳答案
查看编译器的预编译头文件选项。 In GCC ,例如,将 header 作为源传递会导致它被预编译。
它显着减少了我的小测试的时间,但前提是你不计算预编译所花费的时间:
Shadow:code dkrauss$ ls maps*
maps.cpp maps.h maps2.cpp
Shadow:code dkrauss$ cat maps*
#include "maps.h"
using namespace std;
map<int,int> ints;
map<string, string> strings;
map<int, string> is;
map<string, int> si;
int main() {
bang(ints);
bang(strings);
bang(is);
bang(si);
extern void more();
more();
}
#include <string>
#include <map>
template< class K, class V >
void bang( std::map<K,V> &v ) {
v[ K() ] = V();
v.erase( v.begin() );
}
#include "maps.h"
using namespace std;
map<int,int> ints2;
map<string, string> strings2;
map<int, string> is2;
map<string, int> si2;
void more() {
bang(ints2);
bang(strings2);
bang(is2);
bang(si2);
}
Shadow:code dkrauss$ time g++ maps*.cpp -o maps
real 0m1.091s
user 0m0.857s
sys 0m0.132s
Shadow:code dkrauss$ time g++ maps.h
real 0m0.952s
user 0m0.406s
sys 0m0.110s
Shadow:code dkrauss$ ls maps*
maps maps.cpp maps.h maps.h.gch maps2.cpp
Shadow:code dkrauss$ time g++ maps*.cpp -o maps
real 0m0.718s
user 0m0.552s
sys 0m0.095s
Shadow:code dkrauss$
关于c++ - 针对编译时间优化的 STL 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2679717/