C++/STL - Slow? SOLVED

Started by
7 comments, last by Zakwayda 15 years, 5 months ago
Hi Guys! Currently I'm working on a rendering-engine in C++ with OpenGL. So far, everything goes well, thanks to some help over in the "Graphics Programming" board ;). However, I've now replaced some of my model-code for better readability. Specifically, I've replaced static float * and int * arrays that held my vertexbuffer and an indexed geometry in favor of stl::vector template objects. Now, my code is pretty much FUBAR. It's speed has decreased by a factor of approximately 80, according to frame counts. My question here is this: Are stl vectors really that slow, is it just the Debug setting (I'm working with MS VS2003) or is it neither and have I messed up somewhere else, bigtime? I can post code as well, but I think that's a pretty general question... Any help is appreciated, best regards, Lukas [Edited by - dae_coderonin on October 31, 2008 5:53:49 AM]
Advertisement
Use a profiler on a release build to find the culprit.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Thank you, dalleboy, I'll do that.
Never used a profiler before, though.
Where can I find a good/easy to use one?
Hi

I can tell you that using arrays over std::vector is faster. I tested this a while back.
Quote:Original post by dae_coderonin
My question here is this: Are stl vectors really that slow, is it just the Debug setting (I'm working with MS VS2003)



You should NEVER base ANY performance judgements on the debug build of a project. There are many, many things that could be going on behind the scenes in a debug build that slow things down, such as checked allocations and iterations, additional logging, and also some optimizations that more advanced classes may rely on will not happen in debug.
I have some code around that takes a minute to complete in Release mode, and four hours in Debug.

Try it in Release mode first and if you still have a problem it's worth looking into.

It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
Quote:Original post by MadKeithV
Quote:Original post by dae_coderonin
My question here is this: Are stl vectors really that slow, is it just the Debug setting (I'm working with MS VS2003)



You should NEVER base ANY performance judgements on the debug build of a project. There are many, many things that could be going on behind the scenes in a debug build that slow things down, such as checked allocations and iterations, additional logging, and also some optimizations that more advanced classes may rely on will not happen in debug.
I have some code around that takes a minute to complete in Release mode, and four hours in Debug.

Try it in Release mode first and if you still have a problem it's worth looking into.


Alright MadKeithV, thank you.
Just tested in Release mode, and it runs kinda smooth.
Can still use some optimization, but I'll do that when all functionality is implemented. No point in making my code unreadable at that point.

Thank you, guys!
Chack that you're passing containers around by reference and not by value as well.
Define _SECURE_SCL as 0 in project settings. It should significantly speed things up, since it turns off checked iterators. More info.
Construct (Free open-source game creator)
Quote:Original post by guvidu
I can tell you that using arrays over std::vector is faster. I tested this a while back.
This kind of statement is meaningless without supporting data. Can you post your results along with the relevant code and compiler settings?

Devising meaningful performance tests can be tricky. You might very well know what you're doing, but there've been a number of posts on these forums claiming that X is clearly faster than Y, and then we later find out that the test was run using a debug build, or the container in question was being used incorrectly, or something of that sort. As such, a statement such as 'arrays are faster than std::vector' will usually be dismissed out of hand unless details about the test are provided.

@The OP: If it hasn't been mentioned already (and if you're using Visual Studio), make sure to turn off iterator debugging for your full release build. I don't remember the preprocessor definitions off the top of my head, but it's something like _SECURE_SCL and _HAS_ITERATOR_DEBUGGING. For maximum speed, they should both be set to 0 (in VS, it's easiest to do this from the 'preprocessor' configuration settings).

[Oops, AshleysBrain already mentioned the 'iterator debugging' preprocessor settings.]

This topic is closed to new replies.

Advertisement