STL performance problem

I am implementing a approximate string matching algorithm. First I did that in Java and the response time was not good enough to the amount of information I am dealing with. So, I took a C++ compiler - MS VC++ - and ported the application. It uses a lot of <map>, <set>, <list> and <pair> objects and is intrisic slow.
To my surprise the C++ version was even slower; 10 times slower, actually. Even considering this is my first "real world" try with C++, I could not imagine that result. Is the STL really that slow when the objects mentioned before are used? Is there any STL high performance implementation availiable?

The was an article in C/C++ Users Journal comparing pure C functions with std::string. Final result was that STL degrades perfomance. The results were different for different compilers and STL implementations.

The VC STL is probably one of the best in terms of speed. It is written by P.J. Plauger who is just about THE recognized authority on the subject. Most likely the problem is in your algorithm, not in the STL.

Your best bet is to profile the algorithm (VC has a decent profiler) and look for bottlenecks. Try to optimize those. Although it is possible that the best bet is to redesign from scratch, rather than try to remove the bottlenecks.

We can't tell you much more than that, since we don't know wnything about your code.

The was an article in C/C++ Users Journal comparing pure C functions with std::string. Final result was that STL degrades perfomance. The results were different for different compilers and STL implementations. E.g. for one compiler final code took 20.36 seconds while initial (pure C without C++) took only 8.40. But it was mentioned that there are many things to improve how do you use STL. For example using string::compare instead of <,> leaded to avg. 10% increase of performance.

Those sorts of analyisis are very very missleading. It depends intirely on the algorithm. You can easily construct algorithms where the stl class will be better (because of its lazy I/O optimization.) In any case, java uses a reference counted string class that is very similar to the STL string class in VC 6. (The next VC STL string class won't be reference counted and will supposidly be much faster.)

0

Featured Post

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

C++ Properties
One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method. These are sometimes called "smart fields" because you can add logic that is applied automaticall…

The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.