为什么我的STL代码运行这么慢,当我有调试器/ IDE连接? [英] Why does my STL code run so slowly when I have the debugger/IDE attached?

查看:144
本文介绍了为什么我的STL代码运行这么慢,当我有调试器/ IDE连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2008 SP1,在Windows Vista Business x64,四核机器,8gb ram上运行以下代码。



如果我构建一个版本构建,并从命令行运行它,它报告31ms。



以下是时间:(所有Win32版本)




  • DEBUG,命令行:421ms

  • DEBUG,来自IDE:24,570ms

  • ,命令行:31ms

  • RELEASE,从IDE:23,353ms



p>

  #include< windows.h> 
#include< iostream>

#include< set>
#include< algorithm>
using namespace std;

int runIntersectionTestAlgo()
{

set< int> set1;
set< int> set2;
set< int>路口;


//为set1创建100,000个值
for(int i = 0; i <100000; i ++)
{
int value = 1000000000 + i;
set1.insert(value);
}

//为set2创建1,000个值
for(int i = 0; i <1000; i ++)
{
int random = rand()%200000 + 1;
random * = 10;

int value = 1000000000 + random;
set2.insert(value);
}

set_intersection(set1.begin(),set1.end(),set2.begin(),set2.end(),inserter(intersection,intersection.end ;

return intersection.size();
}

int main(){
DWORD start = GetTickCount();

runIntersectionTestAlgo();

DWORD span = GetTickCount() - start;

std :: cout<< span<< milliseconds\\\
;
}


解决方案

在Microsoft调试器windbg,kd,cdb,Visual Studio Debugger)默认强制Windows使用调试堆而不是默认堆。在Windows 2000及更高版本上,默认堆是低碎片堆 ,这是相比调试堆疯狂好。您可以使用 HeapQueryInformation 查询正在使用的堆类型。 / p>

要解决您的特定问题,您可以使用此知识库文章中推荐的许多选项之一:为什么在运行Windows Server 2003,Windows XP或Windows 2000的某些计算机上可能禁用低碎片堆(LFH)机制



对于Visual Studio,我喜欢将 _NO_DEBUG_HEAP = 1 添加到项目属性 - >配置属性 - >调试 - >环境。这总是对我的诡计。


I'm running the following code, using Visual Studio 2008 SP1, on Windows Vista Business x64, quad core machine, 8gb ram.

If I build a release build, and run it from the command line, it reports 31ms. If I then start it from the IDE, using F5, it reports 23353ms.

Here are the times: (all Win32 builds)

  • DEBUG, command line: 421ms
  • DEBUG, from the IDE: 24,570ms
  • RELEASE, command line: 31ms
  • RELEASE, from IDE: 23,353ms

code:

#include <windows.h>
#include <iostream>

#include <set>
#include <algorithm>
using namespace std;

int runIntersectionTestAlgo()
{   

    set<int> set1;
    set<int> set2;
    set<int> intersection;


    // Create 100,000 values for set1
    for ( int i = 0; i < 100000; i++ )
    {
        int value = 1000000000 + i;
        set1.insert(value);
    }

    // Create 1,000 values for set2
    for ( int i = 0; i < 1000; i++ )
    {
        int random = rand() % 200000 + 1;
        random *= 10;

        int value = 1000000000 + random;
        set2.insert(value);
    }

    set_intersection(set1.begin(),set1.end(), set2.begin(), set2.end(), inserter(intersection, intersection.end()));

    return intersection.size(); 
}

int main(){
    DWORD start = GetTickCount();

    runIntersectionTestAlgo();

    DWORD span = GetTickCount() - start;

    std::cout << span << " milliseconds\n";
}

解决方案

Running under a Microsoft debugger (windbg, kd, cdb, Visual Studio Debugger) by default forces Windows to use the debug heap instead of the default heap. On Windows 2000 and above, the default heap is the Low Fragmentation Heap, which is insanely good compared to the debug heap. You can query the kind of heap you are using with HeapQueryInformation.

To solve your particular problem, you can use one of the many options recommended in this KB article: Why the low fragmentation heap (LFH) mechanism may be disabled on some computers that are running Windows Server 2003, Windows XP, or Windows 2000

For Visual Studio, I prefer adding _NO_DEBUG_HEAP=1 to Project Properties->Configuration Properties->Debugging->Environment. That always does the trick for me.

这篇关于为什么我的STL代码运行这么慢,当我有调试器/ IDE连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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