Share via


difftime, _difftime32, _difftime64

Busca la diferencia entre dos veces.

double difftime( 
   time_t timer1,
   time_t timer0 
);
double _difftime32( 
   __time32_t timer1,
   __time32_t timer0 
);
double _difftime64( 
   __time64_t timer1,
   __time64_t timer0 
);

Parámetros

  • timer1
    Finalizar tiempo.

  • timer0
    Inicio.

Valor devuelto

difftime devuelve el tiempo transcurrido en segundos, de timer0 a timer1.El valor devuelto es un número de punto flotante de precisión doble.El valor devuelto puede ser 0, que indica un error.

Comentarios

la función de difftime calcula la diferencia entre los dos valores de hora proporcionados timer0 y timer1.

El valor de hora proporcionado debe caber dentro del intervalo de time_t.time_t es un valor de 64 bits.Así, el final del intervalo se extendido desde 03:14: 7 de enero de 19, 2038 A 23:59: 59, el 31 de diciembre, 3000.El intervalo menor de time_t sigue siendo de medianoche, el 1 de enero de 1970.

difftime es una función inline dependiendo de qué se evalúa como _difftime32 o a _difftime64 si _USE_32BIT_TIME_T está definido._difftime32 y _difftime64 se pueden utilizar directamente para forzar el uso de un tamaño determinado del tiempo.

estas funciones validan sus parámetros.Si alguno de los parámetros es cero o negativo, se invoca el controlador no válido del parámetro, como se describe en. Validación de parámetrosSi la ejecución puede continuar, estas funciones devuelven 0 y errno establecido en EINVAL.

Requisitos

rutina

Encabezado necesario

difftime

<time.h>

_difftime32

<time.h>

_difftime64

<time.h>

Para obtener información adicional de compatibilidad, vea compatibilidad en la Introducción.

Ejemplo

// 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 );
}
  
  
  

Equivalente en .NET Framework

System:: fecha y hora:: Restar

Vea también

Referencia

Compatibilidad de punto flotante

Administración de tiempo

time, _time32, _time64