Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have use different function for sorting like bubble sort..etc now how compare time complexity for all method.i have to include time()function in every function?
Posted

I hate to say it, but there is no simple solution here to give you - execution measurement is a fraught process! :laugh:

The first thing to note is that Time is probably not going to help you - it returns a value which is measured in seconds - which unless you have a very, very slow PC is not going to be anywhere near accurate enough to give you any meaningful results. You need to look at the non-standard timing libraries for your specific system to find one that works to a much finer ghranularity - ticks, milliseconds, or better microseconds.

Secondly, you are going to have problems here, because in order to get any accurate measurements, you need to run the function(s) many times - thousands at the least - to eliminate any variations caused by caching, other threads, memory allocation, and so forth. And that's a problem with a sort function, because it's purpose is to rearrange the data - so you will need to regenerate the data each time, and eliminate the overhead of that from your timings.

Thirdly, you are still going to have problems because some sorting methods are much, much more efficient with data which has some order already. A bubble sort with sorted data will be about as quick as it is possible to be, while a bubble with reverse sorted data will be about as slow as possible! So you probably need to think about a range of datasets to present the functions as well.

Good luck!
 
Share this answer
 
OriginalGriff said wise words about the issue.

BTW under windows you can give a try to the high resolution time stamps through the use of the
C++
QueryPerformanceCounter (QPC)
.

You can find sample here here[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900