a question about efficiency of STL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • palance
    New Member
    • Apr 2008
    • 1

    a question about efficiency of STL

    [code=cpp]
    #include <list>

    int main()
    {
    std::list<int> lst;
    for(int i=0; i<1000; i++)
    {
    for(int x=0; x<5000; x++)
    lst.push_back(x );
    lst.clear();
    }
    return 0;
    }[/code]
    I compiled this code on VC8 (Release version ) and Cygwin G++ 3.4.4 and compare the result :

    $time test_gcc
    real 0m13.100s
    user 0m13.077s
    sys 0m0.031s

    $time test_vc
    real 0m3.552s
    user 0m0.031s
    sys 0m0.015s

    why the difference is so far?
    Last edited by Banfa; Apr 10 '08, 09:40 AM. Reason: Please use the [code]...[/code] tags provided
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Every compiler implements the STL in a different way.
    But i am also surrised to see this much difference

    Raghuram

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      This doesn't even have to be an STL issue, it could simply be a compiler/optomiser issue.

      For instance did you put switches on both compilers to optimise the output exe for time exectution or did you optimise one for time and the other for size?

      For a long while gcc was lagging in producing efficent code to run on Windows (although I thought they had more or less caught up now) and in fact I believe the best compiler you can get for an Intel based PC is the Intel compiler (not too unsurprisingly they understand best how to optimise code to run on their chips).

      The thing is that the way gcc and GNU compilers in general work is to cross compile to an intermediary code (p code?) and then compile that p code into a platform specific exe. This makes it very easy to add a new platform supported by many languages or add a new language to many platforms but the method is generic and because of that it is inherently hard for it to compete on efficiency with a targeted method. That is a compiler targeted at 1 platform and 1 language.

      Like I said I thought the gcc developers had done something clever to get round this to some extent on the later releases so I would try fiddling with the compiler switches as a start.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Whose STL is being used?

        Visual C++ uses Plaugher's templates at Dinkumware.com. These are optimized for speed.

        Comment

        Working...