Last active
February 23, 2017 06:32
-
-
Save RicardoLara/bed8cdf8ee99256bcb5dd59628205d76 to your computer and use it in GitHub Desktop.
Práctica 2 4/5[AA] - Daniel Cruz García
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include "tiempo.h" | |
| void Insercion(int * A, int n){ | |
| int j,i,temp; | |
| for(i=0; i<n; i++){ | |
| temp = A[i]; | |
| j = i-1; | |
| while(A[j] > temp && j >= 0){ | |
| A[j+1] = A[j]; | |
| j--; | |
| } | |
| A[j+1] = temp; | |
| } | |
| } | |
| int main(){ | |
| double utime0, stime0, wtime0,utime1, stime1, wtime1; //Variables para medición de tiempos | |
| int j,i,n; | |
| n = 0; | |
| for(j=0; j<50; j++){ | |
| n += 1000; | |
| printf("------------------- NUMERO %d --------------------- \n",j+1); | |
| int k,A[n],s; k=1; | |
| FILE *fp = fopen("./DatosAleatorios2.txt","r"); | |
| fscanf(fp,"%d",&s); | |
| while(k<n){ | |
| A[k-1] = s; | |
| fscanf(fp,"%d",&s); k++; | |
| } | |
| fclose(fp); | |
| uswtime(&utime0, &stime0, &wtime0); | |
| //printf("Arreglo Original: "); | |
| //for(i=0; i<n; i++) printf("%d ",A[i]); printf("\n"); | |
| Insercion(A,n); | |
| //printf("Arreglo Ordenado: "); | |
| //for(i=0; i<n; i++) printf("%d ",A[i]); printf("\n"); | |
| 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