Efficiency of STL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sakkiharry
    New Member
    • Oct 2007
    • 1

    Efficiency of STL

    Hi,
    Is using STL functions,
    1. More Efficient than using normal for loop for searching operation?
    2. STL for storing the data?

    Please help me in this regard.

    Thanks in Advance,
    sakkiharry
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    1. Have you researched to find what algorithm the STL uses to search?
    2. What data? (ie, type, size, etc...)

    PS - Wikipedia especially, but Google as well, are your friends

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Originally posted by sakkiharry
      Is using STL functions,
      1. More Efficient than using normal for loop for searching operation?
      2. STL for storing the data?
      The answer to question 1 is: YES.
      The answer to question 2 is :YES.

      P.J.Plauger, one of the STL developers has written: If you think you do do this quicker than the STL, then think three times.

      Studies have been done using the various containers and in all cases the STL outperforms handwritten code.

      Personally, I would not go outside the STL unless I had a reason I could write down on paper as to why it is absolutely necessary.

      What does happen is that developers like to write code about things they already know, like a linked list. Using the STL means giving up that hobby and using a standard container. For some, it is just too much and they spend a lot of time (and their company's money) rewriting the STL and doing a poor job of it. I mean, if they couldn't write that linked list, they'd have to work on the application.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by weaknessforcats
        Personally, I would not go outside the STL unless I had a reason I could write down on paper as to why it is absolutely necessary.
        I agree 100% with this.

        It is also important to understand the strengths and weaknesses of the different containers in the STL and choose the right one for the job at hand.

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          Originally posted by weaknessforcats
          Personally, I would not go outside the STL unless I had a reason I could write down on paper as to why it is absolutely necessary.
          And I'll agree. The classes and containers (and everything) in the STL have been carefully written and optimized by teams of experts, so they're pretty much the best things out there in their class. Despite the fact that I've written my own versions of trees/lists/stacks etc. (for learning purposes), that doesn't mean STL isn't infinitely better.

          Comment

          Working...