为什么此代码的调试速度要慢100倍? [英] Why is this code 100 times slower in debug?

查看:86
本文介绍了为什么此代码的调试速度要慢100倍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MSVC 2010。

I'm using MSVC 2010.

我正在尝试从列表中删除重复项(不保留任何重复项)

I'm trying to remove duplicate (without keeping any of them) from a list

在调试模式下,为什么这段代码的速度慢100倍?

Why is this code 100 times slower in debug mode?

还有其他方法可以删除所有等效的对象并使其更快地运行吗?调试模式?

Is there any other way to remove all objects that are equivalent and make it faster in debug mode?

目前我无法使用调试。处理需要几分钟,而要释放几秒钟。

It is to the point I can't use debug at the moment. It take minutes to process while few seconds in release.

void SomeFunction()
{
    std::list<Something> list;
    std::list<Something>::iterator it1;
    std::list<Something>::iterator it2;

    for (it1 = list.begin(); it1 != list.end(); it1++)
    {
        for (it2 = list.begin(); it2!=list.end(); it2++)
        {
            if (it1->SomeValue() == it2->SomeValue())
            {
                if (it1 != it2)
                {
                    list.erase(it1);
                    list.erase(it2);

                    it2 = list.begin();
                    it1 = it2++;
                }
            }
        }
    }
}


推荐答案

通常,由于迭代器调试支持。您可以通过设置 _HAS_ITERATOR_DEBUGGING 来大大加快此过程。 a>到0。

In general, STL is very slow while debugging in Visual Studio due to the iterator debugging support. You can speed this up dramatically by setting _HAS_ITERATOR_DEBUGGING to 0.

这篇关于为什么此代码的调试速度要慢100倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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