C - Measure Function Time Execution -


i want measure elasped time insertion_sort function. but, result 0.0000000 second. can do? tried other time libraries.unfortunatelly, didn't... thanks. writed again.

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h>  int main(void)  {   int number=1;   if(number == 1)   {      struct timeval start, end;      gettimeofday(&start, null);       for(int i=0; i<5;i++)      {      insertion_sort( kelime, n );         }      gettimeofday(&end, null);       printf("elapsed time %.10f",(end.tv_sec * 1000000 + end.tv_usec)-   (start.tv_sec * 1000000 + start.tv_usec));  } 

time has seconds granularity. whereas code microseconds or milliseconds @ worst. use gettimeofday instead has microsecond granularity.

but note both time , gettimeofday gives wall time. if want cpu time clock can used.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -