CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    99

    Angry 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?

  2. #2
    Join Date
    Jul 2008
    Posts
    70

    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.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured