Thread: running time for memchr()

  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,895
    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,895
    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, 11:08 AM
  2. Finding Program Running Time
    By pf732k3 in forum C Programming
    Replies: 6
    Last Post: 03-18-2008, 01:56 PM
  3. Clearing the console
    By beanroaster in forum C++ Programming
    Replies: 53
    Last Post: 09-14-2005, 07: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