Like Tree3Likes
  • 1 Post By cyberfish
  • 2 Post By cyberfish

Class list. Fast IN&OUT

This is a discussion on Class list. Fast IN&OUT within the C++ Programming forums, part of the General Programming Boards category; I have in my application on the client side several lists of data, which are compared, merged and so on ...

  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,183
    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,183
    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,139
    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,183
    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.
    Salem likes this.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,183
    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.
    Salem and Elysia like this.

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, 03: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, 09:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21