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>
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>
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"