How do I compute computational time for my main program? I know there is a ctime object but dont know what is the best way to use it. My Main file calls 2 three functions also.
#include <ctime>
#include <cstdio>
void myfunc(){
//do stuff
unsignedint x=1;
while(x<4294967295){//something that takes a long time to execute (around 4 seconds on my laptop)
++x;}}
int main(){
clock_t ticks=clock();//keeps track of ticks
myfunc();//your function
//update the ticks
ticks-=clock();
ticks=-ticks;
//display the time
printf("myfunc took %i ticks to run.\nPress <ENTER> to exit\n",ticks);
getchar();
return 0;}
First you record the number of ticks before using the function, then you record the number of ticks afterwards.