stl :: hash_set.insert()在调试模式下非常慢 [英] stl::hash_set.insert() is extremely slow in debug mode

查看:165
本文介绍了stl :: hash_set.insert()在调试模式下非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要插入约。在C ++中使用5,000,000个整数到一个hash_set,在调试模式下需要几个小时才能完成循环。在发布模式下,它会减慢程序,大约需要一分钟,这不是很棒,但我可以忍受它。 hash_set是正常的吗?插入应该是O(1)...

I need to insert approx. 5,000,000 integers to a hash_set in C++, it takes many hours to go through the loop in debug mode. In release mode it slows down the program, takes about a minute, which is not fantastic, but I can live with it. Is it normal for hash_set? Insert should be O(1)...

推荐答案

由于迭代器调试支持,在Visual Studio中调试时STL非常慢。

你可以通过设置来显着加快这一点

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





Quelle: http://msdn.microsoft.com/en-us/library/aa985939(v = vs.80).aspx [ ^ ]


如果要编译C ++ / CLI(混合模式)应用程序,则可能需要将性能与.NET容器进行比较。在混合/模式下,它们通常比C ++快得多。



我不知道为什么但是如果你想要一个想法,网上有基准。



顺便说一下,调试C ++ / CLI代码(使用STL)比调试等效的.NET代码慢得多。在某种程度上,类似于编译C#代码的速度要快得多,因为当模板被大量使用时(STL甚至是最差的一些增强代码),编译C ++特别有用。



几年前我开始使用应用程序时,我使用了很多C ++代码,因为我喜欢STL但是多年来,我倾向于使用越来越多的C#代码来避免甚至不存在的问题。 。



这甚至是最糟糕的,因为调试C ++代码不那么友好,因为调试器在检查变量时并不总是显示相关信息。
If you are compiling a C++/CLI (mixed-mode) application, you might want to compare the performative with .NET containers. Often they are much faster than C++ one in mixed/mode.

I don''t know why but there are benchmarks on the web if you want to have an idea.

By the way debugging C++/CLI code (using STL) is sometime much slower that debugging equivalent .NET code. In a way it is similar to the fact that compiling C# code is much faster that compiling C++ particulary when template are used a lot (STL or even worst some boost code).

When I start my application a few years ago, I was using a lot of C++ code as I''d like STL but with years, I tend to do more and more C# code to avoid problems that should not even exists...

This is even worst as debugging C++ code is not as friendly because the debugger is not always displaying relevant information when inspecting variables.


这篇关于stl :: hash_set.insert()在调试模式下非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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