1

I'm using below code to get the total time of my program.

clock_t start=clock();
//doing some work
clock_t end=clock();
printf("%f \n",(double)(end-start)/(double)CLOCKS_PER_SEC);

I'm running my program in virtual machine. It always shows me 0.000000! Do you know why? Is it because of VM?

Sara
  • 2,308
  • 11
  • 50
  • 76

1 Answers1

1

You were trying to print using an integer format specifier with a double value.

Try:

printf("%f \n",(double)(end-start)/(double)CLOCKS_PER_SEC);

EDIT: Just found this answer that should fix your problem.

Community
  • 1
  • 1
Aaron Cronin
  • 2,093
  • 14
  • 13