Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // msvc++ (c)
- // paulogp
- #include <stdio.h>
- #include <conio.h> // getch
- #include <stdlib.h>
- #include <time.h>
- #define MAX 80000
- int main()
- {
- clock_t the_inic_time, the_end_time;
- long int i, j;
- double the_sum, the_vector[MAX];
- // display
- printf("Teste de processamento\n\n");
- printf("\nTeste iniciado... (para interromper o teste pressione as teclas: CTRL+C)\n");
- // initiate random
- srand((unsigned int)time(NULL));
- // random values to vector
- the_inic_time = clock();
- for (j = 0; j < 1000; j++)
- {
- for (i = 0; i < MAX; i++)
- {
- the_vector[i] = (rand() % MAX) + 1;
- }
- }
- the_end_time = clock();
- printf("\nTempo de leitura: %f ms\n", ((double)the_end_time - the_inic_time) / CLOCKS_PER_SEC);
- // sum
- the_inic_time = clock();
- the_sum = 0;
- for (j = 0; j < 1000; j++)
- {
- for (i = 1; i <= MAX; i++)
- {
- the_sum += the_vector[i];
- }
- }
- the_end_time = clock();
- printf("\nTempo de processamento: %f ms\n\n", ((double)the_end_time - the_inic_time) / CLOCKS_PER_SEC);
- // end
- printf("Prima uma tecla para sair do programa!");
- getch();
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement