|
-
September 10th, 2008, 11:37 PM
#1
profiling test on std::vector
hello folks,
my program runs too slow, so i did a profiling test. the result showed that i'm using too many std::vectors.
the profiling tool i'm using is AMD's codeAnalyst , however one weird thing is, the top two functions that have the most time samples are
tan() and strchr() in ntdll.dll
i just don't understand how come these two functions could have something to do with std::vector?
i did a simpler test
the code is easy:
void main(){
for(int i=0;i<4000000;++i)
std::vector<int> a;
};
and once again, the codeAnalyst pointed out the two slowest function
tan() and strchr() in the ntdll.dll
why?
-
September 11th, 2008, 12:45 AM
#2
Re: profiling test on std::vector
Don't know why its picking those out, but I did want to throw one thing out there.
A while back I did some heavy stuff with vector. When I closed visual studio and opened it back up my program was running *a lot* slower. Turned out visual studio set it back to Debug mode.
So make sure you are compiling Release that makes a huge difference. Only other suggestion I have is try other profilers, I like Visual Studio's see if they agree.
-
September 11th, 2008, 03:04 AM
#3
Re: profiling test on std::vector
First, do not profile Debug builds, but only Release builds. Reason is that a Release build is what a client gets, and these should have the optimizations enabled.
In your simple application, you are creating 4 million vectors. No wondering the tools says you're using too many vectors. However, make sure than if you use vectors, and pass vectors to functions, you do it by reference, or constant reference. Otherwise, if you do it by value, it has to make a copy of it, which is always time consuming. Passing by (const) reference means you pass the address of the object, so no time is wasted.
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
|