c++ - 针对编译时间优化的 STL 版本?

标签 c++ stl containers

我正在寻找针对较短的编译时间进行优化的 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/

相关文章:

c++ - 实现迭代器时声明 value_type

c++ - 在定义嵌套类之前声明它们

c++ - 如何使用 "cout"打印数据成员的地址(在类偏移量中)

c++ - C++ 中短格式 "if"的 Python 等效项

c++ - 由于未找到异常语言 "cpp",eclipse 中的 Sonar 分析失败在本地分析中抛出错误

c++ - STL 嵌套容器取消引用错误

c++ - 从 vector 范围中删除特定元素

c++ - std::stack<boost::shared_ptr<T>> 的深拷贝

html - 在容器 div 中滚动 div 不起作用

java - 确定打开了多少顶级容器