std :: map clear()在调试器中的性能? [英] std::map clear() performance in debugger?

查看:364
本文介绍了std :: map clear()在调试器中的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

附加的,微不足道的测试程序测试清空一个简单的std :: map的性能。使用MSVC 2008和2010,当从命令提示符执行时,调试构建将需要<30秒,但是当从调试器中执行时将近3分钟。调用clear()是完全负责的区别。如果我进入调试器,callstack将总是指向HeapFree。

问题:为什么巨大的差异?我可以以某种方式更改调试堆设置,以便在调试器中执行时会很快。

The attached, trivial, test program tests the performance of emptying a simple std::map. Using MSVC 2008 and 2010, the debug build will take <30seconds when executed from a command prompt but almost 3 minutes when executed from within the debugger. The call to clear() is entirely responsible for the difference. If I break into the debugger the callstack will always point to HeapFree.
Question: Why the huge difference? Can I somehow change debug heap settings so it'll be fast when executed in the debugger?

#include <map>

int
main ( int, char )
{
    std::map< time_t, double > test;
    for ( int i = 0; i < 1000000; ++i )
    {
        test[i] = i / 3.14;
    }
    test.clear();
    return 0;
}


推荐答案

尝试设置环境变量_NO_DEBUG_HEAP = 1在程序的初始环境中。这会禁用Windows的内部调试堆,这可能会使调试内存损坏问题变得更加困难。

Trying setting the environment variable _NO_DEBUG_HEAP=1 in the program's initial environment. This disables Windows' internal debug heap, which might make it harder to debug memory corruption problems.

KB文章提到该标志,并且您可以推断,如果程序在没有该环境变量的调试器中运行,则禁用默认(低碎片堆)。另请参阅此博文,其中讨论了调试堆可以将他们的程序减慢3-5倍。

This KB article mentions the flag, and you can infer that the default (low-fragmentation heap) is disabled if the program is run in a debugger without that environment variable. See also this blog post, which discusses how the debug heap can slow down their program by 3-5 times.

这篇关于std :: map clear()在调试器中的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆