difftime, _difftime32, _difftime64
Vyhledá rozdíl mezi dvěma časy.
double difftime(
time_t timer1,
time_t timer0
);
double _difftime32(
__time32_t timer1,
__time32_t timer0
);
double _difftime64(
__time64_t timer1,
__time64_t timer0
);
Parametry
timer1
Čas dokončení.timer0
Počáteční čas.
Vrácená hodnota
difftimeVrátí uplynulý čas v sekundách od timer0 k timer1.Vrácená hodnota je číslo s plovoucí desetinnou čárkou dvojitou přesností.Vrácená hodnota může být 0, označující chybu.
Poznámky
difftime Funkce vypočítá rozdíl mezi dvěma hodnotami zadané doby timer0 a timer1.
Zadaná hodnota času musí vejít v rozsahu od time_t.time_tje hodnota 64-bit.Tedy konec rozsahu bylo prodlouženo z 03:14:07 19. ledna 2038 23:59:59, 31 prosince 3000.Dolní oblast time_t je stále půlnoc 1. ledna 1970.
difftimevložené funkce, který je vyhodnocen buď je _difftime32 nebo _difftime64 podle toho, zda _USE_32BIT_TIME_T je definován. _difftime32 a _difftime64 lze použít přímo, chcete-li vynutit použití určité velikosti typ času.
Tyto funkce ověřují své parametry.Pokud parametrů je nulové nebo záporné, neplatný parametr rutiny je vyvolán, jak je popsáno v Ověření parametru.Pokud je povoleno pokračovat v provádění, vrátí tyto funkce hodnotu 0 a errno k EINVAL.
Požadavky
Rutina |
Požadované záhlaví |
---|---|
difftime |
<time.h> |
_difftime32 |
<time.h> |
_difftime64 |
<time.h> |
Další informace o kompatibilitě naleznete v úvodu tématu Kompatibilita.
Příklad
// crt_difftime.c
// This program calculates the amount of time
// needed to do a floating-point multiply 100 million times.
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <float.h>
double RangedRand( float range_min, float range_max)
{
// Generate random numbers in the half-closed interval
// [range_min, range_max). In other words,
// range_min <= random number < range_max
return ((double)rand() / (RAND_MAX + 1) * (range_max - range_min)
+ range_min);
}
int main( void )
{
time_t start, finish;
long loop;
double result, elapsed_time;
double arNums[3];
// Seed the random-number generator with the current time so that
// the numbers will be different every time we run.
srand( (unsigned)time( NULL ) );
arNums[0] = RangedRand(1, FLT_MAX);
arNums[1] = RangedRand(1, FLT_MAX);
arNums[2] = RangedRand(1, FLT_MAX);
printf( "Using floating point numbers %.5e %.5e %.5e\n", arNums[0], arNums[1], arNums[2] );
printf( "Multiplying 2 numbers 100 million times...\n" );
time( &start );
for( loop = 0; loop < 100000000; loop++ )
result = arNums[loop%3] * arNums[(loop+1)%3];
time( &finish );
elapsed_time = difftime( finish, start );
printf( "\nProgram takes %6.0f seconds.\n", elapsed_time );
}