fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. #define LOOP1 (100)
  5. #define LOOP2 (480000)
  6. #define LOOP3 (10)
  7.  
  8. int main()
  9. {
  10. int a;
  11. clock_t c;
  12.  
  13. for(int l = 0; l < 2; ++l) {
  14. {
  15. // ぱたん1
  16. a = 0;
  17. c = clock();
  18. for(int i(0); i < LOOP1; ++i)
  19. for(int j(0); j < LOOP2; ++j)
  20. for(int k(0); k < LOOP3; ++k)
  21. a ^= k + j + i;
  22. printf("%d, time : %d\n", a, clock() - c);
  23. }
  24.  
  25. {
  26. // ぱたん2
  27. a = 0;
  28. c = clock();
  29. for(int i(0); i < LOOP1; ++i)
  30. for(int j(0); j < LOOP3; ++j)
  31. for(int k(0); k < LOOP2; ++k)
  32. a ^= k + j + i;
  33. printf("%d, time : %d\n", a, clock() - c);
  34. }
  35.  
  36. {
  37. // ぱたん3
  38. a = 0;
  39. c = clock();
  40. int i, j, k;
  41. for(i = 0; i < LOOP1; ++i)
  42. for(j = 0; j < LOOP2; ++j)
  43. for(k = 0; k < LOOP3; ++k)
  44. a ^= k + j + i;
  45. printf("%d, time : %d\n", a, clock() - c);
  46. }
  47.  
  48. {
  49. // ぱたん4
  50. a = 0;
  51. c = clock();
  52. int i, j, k;
  53. for(i = 0; i < LOOP1; ++i)
  54. for(j = 0; j < LOOP3; ++j)
  55. for(k = 0; k < LOOP2; ++k)
  56. a ^= k + j + i;
  57. printf("%d, time : %d\n", a, clock() - c);
  58. }
  59.  
  60. printf("\n");
  61. }
  62.  
  63. return a;
  64. }
  65.  
  66. /*
  67. ローカルでの実行結果
  68.  
  69. 0, time : 1766
  70. 0, time : 1328
  71. 0, time : 1719
  72. 0, time : 1390
  73.  
  74. 0, time : 1766
  75. 0, time : 1375
  76. 0, time : 1672
  77. 0, time : 1359
  78.  
  79. */
  80.  
  81.  
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:22: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
prog.cpp:33: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
prog.cpp:45: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
prog.cpp:57: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
stdout
0, time : 460000
0, time : 470000
0, time : 460000
0, time : 620000

0, time : 460000
0, time : 420000
0, time : 460000
0, time : 630000