Skip to content

Instantly share code, notes, and snippets.

@RicardoLara
Created February 20, 2017 02:07
Show Gist options
  • Select an option

  • Save RicardoLara/d1af9e52b214aa6290b9c13c18f6f7a4 to your computer and use it in GitHub Desktop.

Select an option

Save RicardoLara/d1af9e52b214aa6290b9c13c18f6f7a4 to your computer and use it in GitHub Desktop.
Práctica 1 3/5[AA] - Daniel Cruz García
#include<stdio.h>
#include "tiempo.h"
int MaximoComunDivisor(int m, int n){
int a,b, residuo;
if(m>n){ a=m; b=n; } else { a=n; b=m; }
residuo = 1;
while(residuo > 0){
residuo = a % b;
a = b;
b = residuo;
}
return a;
}
int main(){
double utime0, stime0, wtime0,utime1, stime1, wtime1; //Variables para medición de tiempos
int i,a = 48, b = 33;
int A[] = {2135,43247,812,94,36,45,26,38,561,84,5789,347,351,543,265,37,50,73,11,33,246,3567,57,734,178,384,235,31,3456,2324,3234,55,72,12,32,22,34,561,73,82,73,75,67,61,38,9679,67,47,28,3307834,345781,4,5,7,1,3,2,3,5,7,11,3,2,3,8,9,6,4,2,3,1,4,5,7,1,3,2,3,5,7,11,3,2,3,8,9,6,4,2,3,1,4,5,7,1,3,2,3,5,7,11,3,2,3,3,2,31,3,2,3,5,7,1,3};
for(i=0; i<50; i++){
printf("------------------- NUMERO %d --------------------- \n",i+1);
uswtime(&utime0, &stime0, &wtime0);
printf("El MCD[%d,%d] es: %d\n",A[i],A[i+1],MaximoComunDivisor(A[i],A[i+1]));
uswtime(&utime1, &stime1, &wtime1);
//Cálculo del tiempo de ejecución del programa
printf("\n");
printf("real (Tiempo total) %.10f s\n", wtime1 - wtime0);
printf("user (Tiempo de procesamiento en CPU) %.10f s\n", utime1 - utime0);
printf("sys (Tiempo en acciónes de E/S) %.10f s\n", stime1 - stime0);
printf("CPU/Wall %.10f %% \n",100.0 * (utime1 - utime0 + stime1 - stime0) / (wtime1 - wtime0));
printf("\n");
//Mostrar los tiempos en formato exponecial
printf("\n");
printf("real (Tiempo total) %.10e s\n", wtime1 - wtime0);
printf("user (Tiempo de procesamiento en CPU) %.10e s\n", utime1 - utime0);
printf("sys (Tiempo en acciónes de E/S) %.10e s\n", stime1 - stime0);
printf("CPU/Wall %.10f %% \n",100.0 * (utime1 - utime0 + stime1 - stime0) / (wtime1 - wtime0));
printf("\n");
//******************************************************************
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment