running time for memchr()

This is a discussion on running time for memchr() within the C++ Programming forums, part of the General Programming Boards category; does anyone know the current running time for this c-string function: memchr()? is it constant/O(1), or O(size of string) ?...

  1. #1
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572

    running time for memchr()

    does anyone know the current running time for this c-string function: memchr()? is it constant/O(1), or O(size of string) ?

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  2. #2
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    I don't really get what do you mean by "current running time", but the function
    Code:
    void* memchr(   const void *buf,   int ch,   size_t count );
    returns a pointer to the first occurence of ch in the first count characters of the given buffer.
    If none found, it returns a NULL pointer.

    Hope I answered your question.

    Hint: www.cppreference.com/stdstring_details.html#memchr

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It runs in linear time (O(n)) if that's what you want.

    I'm not sure how you expect a search function on unsorted linear memory to be any faster.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Originally posted by CornedBee
    It runs in linear time (O(n)) if that's what you want.

    I'm not sure how you expect a search function on unsorted linear memory to be any faster.
    not expecting but hoping thanks

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Hoping against all logic?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    >> Hoping against all logic?

    that is what miracles are, aren't they? LOL....I thought that is was linear...but couldn't find any documentation to prove it....

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check number of times a process is running
    By linuxwolf in forum Windows Programming
    Replies: 6
    Last Post: 10-17-2008, 12:08 PM
  2. Finding Program Running Time
    By pf732k3 in forum C Programming
    Replies: 6
    Last Post: 03-18-2008, 02:56 PM
  3. Clearing the console
    By beanroaster in forum C++ Programming
    Replies: 53
    Last Post: 09-14-2005, 08:46 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM

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