【发布时间】:2021-01-02 23:33:26
【问题描述】:
当我在如下循环中声明地图时,我在某种大学征服中进行编码并注意到了一些事情:
for (int i = 0; i < n; i++)
{
map<int, bool> hashMap;
//...
}
花费的时间比:
map<int, bool> hashMap;
for (int i = 0; i < n; i++)
{
hashMap.clear();
//...
}
所以我想知道为什么在循环中声明一个对象比重新初始化它的性能更差?
【问题讨论】:
标签: c++ performance std c++-standard-library