Thread: Class list. Fast IN&OUT

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    4

    Class list. Fast IN&OUT

    I have in my application on the client side several lists of data, which are compared, merged and so on finally giving the user final list of available values for inserting. All those lists are sequences that supports bidirectional iterators (class list).
    What I have in code:
    Code:
    In header: typedef list<string, allocator<string> > muteList;
    In body: 
    muteList tkn_list;
    muteList full_list;
    muteList diff_list;
     
    tkn_list = GetTakenList(ActLev);
    full_list = FullMutationList(ActLev);
    set_difference (full_list.begin(), full_list.end() ,tkn_list.begin(), tkn_list.end(),inserter(diff_list,diff_list.begin()));
    tkn_list is one which is getting its values from DB in TclientDataSet. I’m feeding it with data using While EOF loop.
    I believe this is not good and I know this is no fast. Could anyone help me by pointing to the more sound way. TclientDataSet has a Data property of OleVariant type. In my case it is filled with a plain list of strings. I wander if there is a way to copy its data to list sequence (or to get its data as a list sequence) in single operator. May be by casting OleVariant to pointer to list or something like that.
    Actually I never used class list. It is not my usual level of programming. Additionally question is: how to send data from list to data controls without loop?
    All suggestions will be more than appreciated.
    Alex

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Did you profile your code?

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    4
    I don't actually understand what you are getting at. In code part I'm just giving several strings to illustrate what I'm talking about.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    You said you believe one part of your code is not fast enough and is slowing the program down. Have you actually profiled to verify that is the case, or are you just guessing?

    Programmers are typically very bad at guessing where bottlenecks are, and end up wasting a lot of time optimizing a part of code that doesn't matter anyways.

    Always make sure with a profiler that what you believe is slow is actually slow, before diving in and start optimizing.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    4
    Well, I'm just guessing. But I know lists are working faster then datasets. Knowledge how to get data in&out lists quickly would show how fast are other ways. I spent considerable amount of time trying to resolve this problem myself but couldn't. Now I rely on the help of this forum.

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    As already said, profile your code. If you are working with a database, probably over the network, my guess would be that your profiling will show you that querying from a remote database is slower than any code your wrote. If (!) that is the case (check it!) then you should look into your driver's API manual to optimize query and network performance.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Well, I'm just guessing. But I know lists are working faster then datasets. Knowledge how to get data in&out lists quickly would show how fast are other ways. I spent considerable amount of time trying to resolve this problem myself but couldn't. Now I rely on the help of this forum.
    Yes, a binary search tree (common implementation of set) is probably faster than a list. For large lists, that you need to do a lot of insertions/searches in, very frequently.

    The problem is, if your network access takes 99.9% of the time, and whatever you do with the list takes 0.1%, even if you make your list infinitely fast, your program will still only be 0.1% faster. Is it worth your time, risk adding bugs, increased complexity, and reduced maintainability, to get that 0.1% performance increase?

    Why not profile your code and find out what REALLY is taking up all the time? Profiling should always be the first step in optimization.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by cyberfish
    Yes, a binary search tree (common implementation of set) is probably faster than a list. For large lists, that you need to do a lot of insertions/searches in, very frequently.

    The problem is, if your network access takes 99.9% of the time, and whatever you do with the list takes 0.1%, even if you make your list infinitely fast, your program will still only be 0.1% faster. Is it worth your time, risk adding bugs, increased complexity, and reduced maintainability, to get that 0.1% performance increase?
    If diff_list is really supposed to be a set, then std::set or std::unordered_set may be more appropriate to begin with, even if it is not an optimisation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Nov 2011
    Posts
    4
    Thank you all for your participation. I cannot not agree with you. But it is a pity that I rest with holes in my education.

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    It's better to not learn a bad habit than learn a bad habit.

    Premature optimization is a very common beginner mistake, that has wasted people countless hours, for exactly nothing, besides bad code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list-------------------plzzzz i need the code fast
    By princess_00 in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2011, 09:39 PM
  2. Replies: 6
    Last Post: 02-27-2009, 04:43 PM
  3. Fast way to check list of 0 or 1 values?
    By DrSnuggles in forum C++ Programming
    Replies: 21
    Last Post: 08-05-2008, 08:13 AM
  4. traversing a linked list with a node and list class
    By brianptodd in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2003, 11:57 AM
  5. Replies: 1
    Last Post: 12-11-2002, 10:31 PM