6.22.8 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, both MPLAB XC16 and XC-DSC compilers returns the time as instruction cycles
so difftime
returns the number of ticks between t1
and
t0
.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <time.h>
#include <stdio.h>
volatile int i;
int main(void)
{
time_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