Mudanças entre as edições de "ADS29009-2019-1"
Ir para navegação
Ir para pesquisar
(Criou página com ' <code> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h> int main() { long int i; double tempo_bloco; for (i=0;i<23;i+...') |
|||
Linha 1: | Linha 1: | ||
− | |||
<code> | <code> | ||
+ | //Modificado de https://www.geeksforgeeks.org/measure-execution-time-with-high-precision-in-c-c/ | ||
#include <sys/time.h> | #include <sys/time.h> | ||
#include <sys/types.h> | #include <sys/types.h> |
Edição das 15h45min de 12 de fevereiro de 2019
//Modificado de https://www.geeksforgeeks.org/measure-execution-time-with-high-precision-in-c-c/
- include <sys/time.h>
- include <sys/types.h>
- include <unistd.h>
- include <stdio.h>
int main()
{
long int i;
double tempo_bloco;
for (i=0;i<23;i++) {
if (fork()==0) {
struct timeval start, end;
gettimeofday(&start, NULL);
for (i=0; i<10000000000L; i++)
{
}
gettimeofday(&end, NULL);
tempo_bloco = (end.tv_sec - start.tv_sec) * 1e6;
tempo_bloco = (tempo_bloco + (end.tv_usec -
start.tv_usec)) * 1e-6;
printf("Tempo = %lf\n", tempo_bloco);
return 0;
}
}
}
</syntaxhighlight>