difftime Function

Find the difference between two times.

Include

<time.h>

Prototype

double difftime(time_t t1, time_t t0);

Arguments

t1
ending time
t0
beginning time

Return Value

Returns the number of seconds between t1 and t0.

Remarks

By default, the 16-bit compiler returns the time as instruction cycles so difftime returns the number of ticks between t1 and t0.

Example

#include <time.h>
#include <stdio.h>

volatile int i;

int main(void)
{
  clock_t start, stop;
  double elapsed;

  start = clock();
  for (i = 0; i < 10; i++)
    stop = clock();
  printf("start = %ld\n", start);
  printf("stop = %ld\n", stop);
  elapsed = difftime(stop, start);
  printf("Elapsed time = %.0f\n", elapsed);
}

Example Output

start = 0
stop = 317
Elapsed time = 317