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?
Re: vstudio, debug, release and assembler
Quote:
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 ...
Quote:
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 )
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.
Re: vstudio, debug, release and assembler
Quote:
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.