Advertisement
paulogp

teste

Aug 2nd, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. // msvc++ (c)
  2. // paulogp
  3.  
  4. #include <stdio.h>
  5. #include <conio.h> // getch
  6. #include <stdlib.h>
  7. #include <time.h>
  8.  
  9. #define MAX 80000
  10.  
  11. int main()
  12. {
  13.     clock_t the_inic_time, the_end_time;
  14.     long int i, j;
  15.     double the_sum, the_vector[MAX];
  16.  
  17.     // display
  18.     printf("Teste de processamento\n\n");
  19.     printf("\nTeste iniciado... (para interromper o teste pressione as teclas: CTRL+C)\n");
  20.    
  21.     // initiate random
  22.     srand((unsigned int)time(NULL));
  23.    
  24.     // random values to vector
  25.     the_inic_time = clock();
  26.  
  27.     for (j = 0; j < 1000; j++)
  28.     {
  29.         for (i = 0; i < MAX; i++)
  30.         {
  31.             the_vector[i] = (rand() % MAX) + 1;
  32.         }
  33.     }
  34.    
  35.     the_end_time = clock();
  36.     printf("\nTempo de leitura: %f ms\n", ((double)the_end_time - the_inic_time) / CLOCKS_PER_SEC);
  37.    
  38.     // sum
  39.     the_inic_time = clock();
  40.  
  41.     the_sum = 0;
  42.     for (j = 0; j < 1000; j++)
  43.     {
  44.         for (i = 1; i <= MAX; i++)
  45.         {
  46.             the_sum += the_vector[i];
  47.         }
  48.     }
  49.    
  50.     the_end_time = clock();
  51.    
  52.     printf("\nTempo de processamento: %f ms\n\n", ((double)the_end_time - the_inic_time) / CLOCKS_PER_SEC);
  53.    
  54.     // end
  55.     printf("Prima uma tecla para sair do programa!");
  56.     getch();
  57.    
  58.     return (0);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement