Difftime Function

  • It is used for returning the difference, in seconds, between time1 and time2( time2 - time1) .
  • The returned value is in floating point double .


  • Syntax:

       difftime(time_t time2, time_t time1);
    
    

    Example:

    
     #include <time.h>
    
      #include <stdio.h>
    
    
    
      int main()
    
      {
    
        time_t begin, end;
    
        volatile long unsigned t;
    
        begin = time(NULL);
    
        for(t=0;t<700; t++) ;
    
        end = time(NULL);
    
        printf("Loop used %f seconds.\n", difftime(end, begin));
    
    
    
        return 0;
    
      }
    
          
    Back