如何在c++中访问映射中的映射.?性能问题
How to access a map within a map in C++ ..? Performance issue?
typedef map<int, string> iMap;
typedef map<double, innerMap> OutMap;
OutMap mx;
map<double, iMap >::iterator it_out;
map<int, string>::iterator it_i;
for ( it_out=mx.begin() ; it_out != mx.end(); it_out++ ) {
cout << "nnNew elementn" << (*it_out).first << endl;
for( it_i=(*it_out).second.begin(); it_i != (*it_out).second.end(); it_out++)
cout << (*it_i).first << " => " << (*it_i).second << endl;
}
我很确定上面的代码是好的…有性能问题吗?
不能再改进了,除了
- 您可以使用预增量而不是后增量,即
++it_out
而不是it_out++
。 - 可以使用
'n'
代替endl
。使用'n'
可以在合理的范围内提高输出操作的性能,因为endl
首先将'n'
放入输出缓冲区,然后将其刷新到目标(本例中为stdout
),从而使其操作缓慢。
注意,应该在内部for
循环中增加it_i
(而不是it_out
)。我想这是一个打字错误。
相关文章:
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 与多个 for 循环与单个 for 循环 wrt 相关的性能从多映射获取数据
- 一维数组映射方式的性能差异问题
- C /C#Interop中的内存映射和P/调用性能
- 具有良好性能的c++映射实现
- 两个映射之间的分配-移动语义和性能
- 内存中 Boost r 树与映射文件中的性能差异
- 字符串与哈希作为映射键 - 性能
- 性能映射 C++ 查找(G++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3))
- 阵列与映射的性能
- std::映射标准分配器性能与块分配器
- 循环文件映射会降低性能
- c++中嵌套三个映射Vs单独映射的性能
- 如何在c++中访问映射中的映射.?性能问题
- 矢量与映射性能混淆
- STL哈希表[无序映射]查找性能与大小
- 转换c++映射到C数组-性能
- 映射性能问题
- 映射模式在多线程程序中的性能低于预期(4倍加速vs 8倍加速)
- 映射与C++中的多映射(性能)