28 lines
598 B
C
28 lines
598 B
C
|
#include <stdio.h>
|
||
|
#include <math.h>
|
||
|
#include <sys/time.h>
|
||
|
|
||
|
int main() {
|
||
|
struct timeval start, end;
|
||
|
double result;
|
||
|
|
||
|
/*Enregistrez le temps de début*/
|
||
|
gettimeofday(&start, NULL);
|
||
|
|
||
|
/* Effectuez le calcul un million de fois */
|
||
|
int i;
|
||
|
for (i = 0; i < 1000000; ++i) {
|
||
|
result = sqrt(2.0);
|
||
|
}
|
||
|
|
||
|
/* Enregistrez le temps de fin */
|
||
|
gettimeofday(&end, NULL);
|
||
|
|
||
|
/* Calculez le temps écoulé en microsecondes */
|
||
|
long elapsed_time = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
|
||
|
|
||
|
printf("%ldμs\n", elapsed_time);
|
||
|
|
||
|
return 0;
|
||
|
}
|