Solved

STL performance problem

Posted on 2000-04-12
5
230 Views
Last Modified: 2010-04-10
 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?

             Thanks in advance,

               Paulo Urbano.
0
Comment
Question by:pgau061099
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 2709974
You need to optimize your algorithm.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2710119
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.
0
 
LVL 5

Accepted Solution

by:
proskig earned 100 total points
ID: 2710877
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.
0
 

Author Comment

by:pgau061099
ID: 2711904
Thanks for the help.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2711984
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question