Thread: measure run time?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    You can approach it in two ways. One is use the OS tools to get the runtime stats or plug in calls to the time() functions to do it for you. On *nix systems, invoke the executable thro' timex, as in
    Code:
    timex <exe_name>

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    In that second function, "else high = mid - 1;" isn't technically correct. It should be just "else high = mid;" because x may still equal v[mid].

    cyberfish:
    I would not test the speed of these functions by repeatedly searching for the same value. For example if you were searching for 7 then the first function would clearly win, but when searching for anything other than 3, 7, 11, or any item not present in the array at all, the second one will win.
    I would speed test it on random numbers equally distributed in the range 0-14. Then you'll know which is faster overall.
    You're also passing in the wrong value for n. It should be sizeof(array) i.e. Seven, not Six, so it wont find 13 anyway because of this, in the code you posted.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. time measure (net and gross) with pthreads under linux
    By mynickmynick in forum Linux Programming
    Replies: 12
    Last Post: 12-01-2008, 07:39 AM
  2. Measure time
    By anirban in forum C Programming
    Replies: 5
    Last Post: 06-12-2008, 03:53 AM
  3. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 07:11 AM
  4. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM