|
-
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.
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
|