Jump to content

Analysing different sorting algorithms

I have to implement sorting algorithms for college, using c, and also analyze, compare and graph the results for different sizes and inputs. How can I create a spreadsheet or something to save the info to graph later and run the program by itself? Like the video below @6:00. Also the pdf explaining, in Portuguese, the work: https://sites.google.com/site/nataliacefetmg/home/laed1_20172/TP2.pdf?attredirects=0

 

 

Link to comment
https://linustechtips.com/topic/856289-analysing-different-sorting-algorithms/
Share on other sites

Link to post
Share on other sites

10 minutes ago, gabrielcarvfer said:

@IgorM, as noctis081 said, just create a CSV file. Open a file in text mode and program your function to write something like that, and put the values you've measured between those commas.


,10^1,10^2,10^3,10^6,10^9,10^12,10^15
bubble,,,,,,,
quick,,,,,,,
merge,,,,,,,
radix,,,,,,,

BTW, if you're doing that kind of comparison with huge sets of numbers, remember to limit the time of the program/function, and interrupt in case it takes too long, then write something on the place, like "ran out of time".

For measuring the run time, is this enough?

 

time_t start,end;     
double dif;     
time (&start);
//algorithm 
time (&end);     
dif = difftime (end,start);

 

Link to post
Share on other sites

9 hours ago, IgorM said:

For measuring the run time, is this enough?

 


time_t start,end;     
double dif;     
time (&start);
//algorithm 
time (&end);     
dif = difftime (end,start);

 

I'd use 'clock' :

//Include header "time.h"

clock_t start = clock();
clock_t elapsed;

//Call algorithm under test here.

elapsed = clock() - start;
int milliSeconds = elapsed * 1000 / CLOCKS_PER_SEC;
printf("Algorithm took %d milliseconds!\n", milliSeconds);

Clock returns the CPU time consumed by the program, not real time, which is closer to what you actually want imho. Real time execution of your algorithm can depend on other things, like another process hogging the CPU.

 

Also note that any tests you perform this way will only give you information about the relative performance of different algorithms on the platform you're testing on and will in no way be a final truth. For example, some algorithms that theoretically should be fast could actually be very slow on a PC if they're cache unfriendly. But that same algorithm might be the fastest when tested on another, cache-less, platform.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×