Last active
February 23, 2017 06:31
-
-
Save RicardoLara/844e7340c506a870df2dc5fd196b8b88 to your computer and use it in GitHub Desktop.
Práctica 2 5/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 Seleccion(int * A, int n){ | |
| int temp,k,i,p; | |
| for(k=0; k < n-1; k++){ | |
| p = k; | |
| for(i= k+1; i<n; i++) | |
| if(A[p] > A[i]) p = i; | |
| if(p != k){ | |
| temp = A[k]; | |
| A[k] = A[p]; | |
| A[p] = 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"); printf("\n"); | |
| Seleccion(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