fork(1) download
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. int minhafuncao(){
  5. int x = 0;
  6. x++;
  7. return x;
  8. }
  9.  
  10. int main () {
  11. clock_t begin, end;
  12. double time_spent;
  13. int x;
  14.  
  15. begin = clock();
  16. for (int i = 0; i < 300000000; i++);
  17. end = clock();
  18. time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  19. printf ("Tempo gasto %.2lf segundos.\n", time_spent);
  20.  
  21. begin = clock();
  22. for (int i = 0; i < 300000000; i++) minhafuncao();
  23. end = clock();
  24. time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  25. printf ("Tempo gasto %.2lf segundos.\n", time_spent);
  26.  
  27. begin = clock();
  28. for (int i = 0; i < 300000000; i++) x++;
  29. end = clock();
  30. time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  31. printf ("Tempo gasto %.2lf segundos.\n", time_spent);
  32. x++;
  33. return 0;
  34. }
Success #stdin #stdout 3.55s 2008KB
stdin
Standard input is empty
stdout
Tempo gasto 1.03 segundos.
Tempo gasto 1.43 segundos.
Tempo gasto 1.09 segundos.