Re: bsearch in C

Discussion in 'C Programming' started by Artie Gold, Aug 7, 2003.

  1. Artie Gold

    Artie Gold Guest

    Edward A Thompson wrote:
    > Is there any common knowledge out there about what the threshold for
    > bsearch (stdlib.h) performing better than a sequential search of an
    > array? If I have an array of 600 structure vs 6000?


    There's no way to make any blanket predictions on this one; it depends
    on the size of the struct, the number of structs, the particular
    implementation of bsearch in your standard library, the pattern of
    searches you're actually performing, cache interaction, etc. etc.

    The best thing to do is to choose one or the other, profile your program
    to see if it causes a bottleneck and, if it does, try the other way and
    see if it helps.

    All that said, bsearch() is probably the way to go in general -- if the
    search space is small it can't be more costly by too much and it will
    scale as the search space grows.

    HTH,
    --ag

    --
    Artie Gold -- Austin, Texas
     
    Artie Gold, Aug 7, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Heathfield

    Re: bsearch in C

    Richard Heathfield, Aug 7, 2003, in forum: C Programming
    Replies:
    0
    Views:
    412
    Richard Heathfield
    Aug 7, 2003
  2. Eric Sosman

    Re: bsearch in C

    Eric Sosman, Aug 7, 2003, in forum: C Programming
    Replies:
    9
    Views:
    521
    Richard Heathfield
    Aug 12, 2003
  3. Ramprasad A Padmanabhan

    a small bsearch example

    Ramprasad A Padmanabhan, Oct 28, 2003, in forum: C Programming
    Replies:
    1
    Views:
    3,798
    Mark Gordon
    Oct 28, 2003
  4. Ramprasad A Padmanabhan

    bsearch script segfault

    Ramprasad A Padmanabhan, Dec 4, 2003, in forum: C Programming
    Replies:
    11
    Views:
    504
    Ramprasad A Padmanabhan
    Dec 5, 2003
  5. Angus Comber

    Struggling with bsearch - on a struct!

    Angus Comber, Feb 5, 2004, in forum: C Programming
    Replies:
    4
    Views:
    361
    Al Bowers
    Feb 6, 2004
Loading...

Share This Page