Last active
February 23, 2017 06:36
-
-
Save RicardoLara/9e4477ca766210ebfa0980e7c332f7bd to your computer and use it in GitHub Desktop.
Práctica 1 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 BurbujaSimple(int * A, int n){ | |
| int i,j,temp; | |
| for(i=0; i<n; i++) | |
| for(j=0; j<n-1; j++) | |
| if(A[j] > A[j+1]){ | |
| temp = A[j]; | |
| A[j] = A[j+1]; | |
| 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"); | |
| BurbujaSimple(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