CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 44

Threaded View

  1. #24
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Need advice - what to use CStringArray or CStringList

    For example, if you just timed this search:
    Code:
    MapCStringToCString::iterator itFound = myData.find( strToSearch );
    if ( itFound != myMap.end() ) 
    {
       // we've found the name.  
       itFound->first // is the lower case version of the found name
       itFound->second //  this is the original case version of the name
    }
    Compared with your loop, you will see that this method runs rings around using arrays and looping methods. The only way the map wouldn't be faster is if your item in the array is within the first 15 or so elements in the array, and even then, the array method could be slower.

    If the items your finding are in the middle of your array, you do the math. You're calling CompareNoCase() on average 50,000 times to find one item. With the map, you're calling the straight compare (actutally the CString's operator ==) a maximum of 16 times. There really isn't any doubt which would be faster.

    Also for Visual C++, you need to set the preprocessor flag to enable full optimizations for STL components. That preprocessor flag is _SECURE_SCL=0 (add this to your preprocessor settings and rebuild your release version of the app). You will probably see a dramatic speed increase in the map method.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; September 25th, 2009 at 04:22 AM.

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