Link to home
Start Free TrialLog in
Avatar of BdLm
BdLmFlag for Germany

asked on

TList vs. Vector // Delphi&Pascal vs. C++ // MS vs. Borland .....

----  a general question ----

How to compare Pascal TList Class vs. C++  vector and Maps , in terms of performance  (insert, update, ...)and coding properties (readability of code, efficiency of the programmer)

Any good link or article is needed.

Is the lack of a STL in Delphi a major drawback, will this help C++ to stay a more imprortant programming language compared to Pascal?

Best

Bdlm
SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dbkruger
dbkruger

Realistically, Borland is a small abberation, and even if you don't love Microsoft (I don't) the world uses C++, Java, and C#. So in terms of the market, Delphi is a lost cause. I'm not commenting on the merits, because I don't know Delphi.

In terms of compile time, Java with Eclipse is very fast because it's incrmenetal, though it's not as fast as Delphi, probably. And that does make a big difference in programmer productivity. C++ has the most expressive power, which is occasionally really useful. When writing mathematical code, the ability to use overloaded operators and have vector equations look as they should is unbeatable.

Templates are a compile time mechanism that is a double win -- the resulting code can be super fast and efficient, while types are checked at compile time. If I want a list of Elephants, I don't want zebras creeping in there, only to crash at runtime, I want to know at compile time that I did something illegal.

Avatar of BdLm

ASKER

     The delphi / pacal code ...
------------------------------------------------------
      //  loop through all elements
      for i := 0 to MyNetList.Count -1 do
         begin
           myElement := MyNetList.Items[i];
           for j:=0 to MyElement.Nodes.Count-1 do
              begin
              If BiasNodes.IndexOf(MyElement.Nodes[j])=-1 then BiasNodes.Add(MyElement.Nodes[j]);
              end;
         end;


C++  STL   Code
---------------------

    for(std::vector<unsigned long>::const_iterator i = m_VectorElementID.begin();
            i!= m_VectorElementID.end(); ++i)
      {
            if(*i==id)
                  return ;            
      }
      m_VectorElementID.push_back(id);
      return;


here a short code comparisons, not same functionallity, but same complexity.
I can't post both applications code here.

We used a first application, written in pascal to read a txt file with 50,000 data records, store them in a Tlist, do some tiny modifications and dump the new List in  an XML File.  We used MSXML 6 API for  writeing  the XML file.  Run Time for 50.000 recoreds a  ~  minutes.

The second application, written in C++ reads this XML file, store the data in a MAP (dynamic array, our replacement for the TList Class from Pacal) and finally we have  to do other operations. Just reading the XML  and creating the MAP takes more then 2 hours. Again we used MS XML. With this ~ 100 times slower data processing we can not reach our performance targets

We have to access single records from our dynamic array, we have to modify single elements in this array, therefore we think, The pacal TList is much better than a vector or a Map from STL C++.
I want to get proofs or inputs how to compare this.  
I believe that the problem is somewhere between the keyboard and your chair. I cannot see any similarity between the two code fragments. The control structures are completely different... also the operated data. It is impossible to comment on your XML example.

Some more comments: The std::map is not a dynamic array, it is a look-up table (the term map is generally used for that kind of data structure). The std::vector is a dynamic array, but it is not a list. List is not an array and if indexing of the list is syntactically allowed, then it will always be slower than the std::vector (in principle).

You should show how your XML records look like and what kind of processing you do. If processing the 50.000 records takes 2 hours, then you are processing about 7 records per second which is unrealistic for any usual program (even written in the scripting language).
Avatar of BdLm

ASKER

in both programs we init a dynamic array of a  defined Datastructure.   Data stuct look like
AElement =  .....  many type    subDynArray  :  Dynamic array  of  ASubdatatype;
What we have to execute in our program is llok for a Index of an Element, find the Index of a Subdatatype and to some small calc.
Our believe is, that the Indexof, Find an Element, Loop thorugh all elements is significant slower for vector and map  as for TList.  

For coorect analysis we should write the identical code in both languages and do our tests,
but I want to avoid this effort wuth with discussion here, looking for a explanation.
         
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you really want to search for a content based on some key (say identification), you should use one of the avaliable map<> structures. Try this:

=============================================
#include <map>
#include <iostream>

using namespace std;

int main()
{
    map<long, size_t> m;
    long MAX = 50000;
   
    cout << "\nassign...";
    for (long i = 0; i < MAX; ++i)
    {
        long id = i * 2;         // just to simulate the ID
        size_t content = i * 3;  // ... and the content
        m[id] = content;         // insert the content for the id
    }


    cout << "\n";    
    cout << "id = 4; value = " << m[4] << "\n";
    cout << "id = 30000; value = " << m[30000] << "\n";

    cout << "\n(the end)\n";

    return 0;
}
=============================================

Use "// only to optimize allocation" in the previous example instead of "# ..." (my mistake).
Avatar of BdLm

ASKER

many thanks in advance for you post,  I will check this code and than accept the question
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BdLm: "We used a first application, written in pascal to read a txt file with 50,000 data records, store them in a Tlist, do some tiny modifications and dump the new List in  an XML File."

The question is whether you should not focuse more on searching for the "right" solution instead of focusing on improving the ad-hoc solution copied from the old application. In my opinion, you should learn basics of XML processing. It seems that some implementation of a SAX based parser may be the right approach for you (http://en.wikipedia.org/wiki/SAX). As you are using Windows, you can use MSXML components by Microsoft (http://en.wikipedia.org/wiki/MSXML) or XmlLite (http://msdn2.microsoft.com/en-us/library/ms752872.aspx).

I personally would probably start with samples that use XmlLite (http://msdn2.microsoft.com/en-us/library/ms752864.aspx).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
developmentguru: Well, it is always good to think about a solution. I agree that "rely on obscure 3rd party library" only because someone said it can be used is not good. However, "reinventing the wheel" in the case it is just around the corner is also not good. It is good to learn and to work hard all the time. However, in my opinion, it is better to use your creativity for the things that have not been solved, yet.

There is no "the best programming language". Both C++ and Delphi are not exceptions. But I have to partly agree with dbkruger about positions of the two languages. I believe that C++ is still more powerful and versatile. The dark side of C++ is that you have to learn more to be efficient in it. But after that, you are not limited. You can use your creativity the way it cannot sometimes be done in other languages.

To be short and back to the original question... I strongly believe that simply "using C++ instead of Delphi" is the reason for slowdown computation.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER



We evaluated the code in more detail, as we use many insert elements in a list, search for a Element in List, we can't compare directly our delphi and our C++ application.  .-((

the Delphiapplication  does the operation in one direction , with the c++ app. we calculated the opposite direction.

MSXML and the msxl.dll seem to work fine for both compilers. The difference in performance is created by a difference in List and vector operations. we have to eval. out code in more details.