-
July 30th, 2010, 05:17 AM
#1
vstudio, debug, release and assembler
I've been using vstudio's debug and goto assembler functions recently, and I had a few questions:
For starters, does it make any sense to debug a release build? If I understand correctly, the debug symbols may slow down the program, but the final assembly should be the same?
I was trying to see if I was better of using 2 iterators to "add two vectors", or just use 1 shared index. This is my test code:
Code:
#include <iostream>
#include <vector>
int main()
{
system("pause");
std::vector<int> a(10000);
std::vector<int> b(10000);
for (size_t i = 0; i!=10000; ++i)
{
a[i]+=b[i];
}
int* pa = &a[0];
int* pb = &b[0];
int* const pEnd = pa+a.size();
for (;pa!=pEnd; ++pa, ++pb)
{
*pa+=*pb;
}
std::vector<int>::iterator ita = a.begin();
std::vector<int>::iterator itb = b.begin();
std::vector<int>::iterator const itEnd = a.end();
for (;ita!=itEnd; ++ita, ++itb)
{
*ita+=*itb;
}
}
Looking at dissambly, VS is terrible at optimizing the iterators: tons of instructions, bunches of function calls...
The same code with pointers was optimized to 5 assembly instructions, of which 1 single jump(!)
I find it strange that in release, I get this order of performance :
pointer > index > iterator
Now I did not time the program, and I don't really want to anyways, the goal here is trying to understand optimizations.
am I doing something fundamentally wrong trying to look at a release build? Does VS have some kind of safe vector iterator even in release?
Last edited by monarch_dodra; July 30th, 2010 at 05:25 AM.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
July 30th, 2010, 05:35 AM
#2
Re: vstudio, debug, release and assembler
Originally Posted by monarch_dodra
Does VS have some kind of safe vector iterator even in release?
surprisingly, yes it does ! take a look at this post where I made exactly the same mistake ...
Originally Posted by monarch_dodra
If I understand correctly, the debug symbols may slow down the program, but the final assembly should be the same?
no, checked iterators apart some optimization are disabled in debug builds ( for example I read somewhere that RVO is disabled in debug builds in some vc++ versions )
-
July 30th, 2010, 05:44 AM
#3
Re: vstudio, debug, release and assembler
Ran some testing, the assembler confirms the code is now very optimized. Thanks for confirming the iterator was range checked in release, and, more importantly, how to deactivate this.
PS. I'd rate, but I have to spread some around first.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
July 30th, 2010, 08:19 AM
#4
Re: vstudio, debug, release and assembler
For starters, does it make any sense to debug a release build? If I understand correctly, the debug symbols may slow down the program, but the final assembly should be the same?
Sometimes. You often do with games, for example, because performance can be unusably bad on the debug builds.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|