Pierre Angelo

Generation

generate functionWed, 05 Apr 2023

¿Cómo mostrar por pantalla el tiempo transcurrido?

#include <time.h> #include <stdio.h> #define BILLION 1000000000L; int main() { struct timespec start, stop; double accum; if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) { perror( "clock gettime" ); exit( EXIT_FAILURE ); } /* Do busy work. */ accum = 0; for( int i=0; i<100000000; ++i ) accum += i*i; if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ) { perror( "clock gettime" ); exit( EXIT_FAILURE ); } printf( "%lf\n", ( stop.tv_sec - start.tv_sec ) + (double)( stop.tv_nsec - start.tv_nsec )/(double)BILLION ); return 0; }

Questions about programming?Chat with your personal AI assistant