fork download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <cstdlib>
  4.  
  5. class Duration {
  6. std::chrono::high_resolution_clock::time_point beg, duration;
  7. public:
  8. Duration() {
  9. beg = std::chrono::high_resolution_clock::now();
  10. }
  11. ~Duration() {
  12. duration = std::chrono::high_resolution_clock::now();
  13. std::cout << std::chrono::duration_cast<std::chrono::microseconds>(duration - beg).count() / 1000 << "ms" << std::endl;
  14. }
  15. };
  16.  
  17. const int N = 10000000;
  18.  
  19. void func1()
  20. {
  21. return;
  22. }
  23.  
  24. void func2()
  25. {
  26. return;
  27. }
  28.  
  29. void func3()
  30. {
  31. return;
  32. }
  33.  
  34. void func4()
  35. {
  36. return;
  37. }
  38.  
  39. int main()
  40. {
  41. void (*func[])() = { func1, func2, func3, func4 };
  42.  
  43. {
  44. std::cout << "単一関数コール" << std::endl;
  45. Duration d;
  46.  
  47. for (int i = 0; i < N; i++)
  48. func[0]();
  49. }
  50.  
  51. {
  52. std::cout << "ランダム関数コール" << std::endl;
  53. Duration d;
  54.  
  55. for (int i = 0; i < N; i++)
  56. func[std::rand() % 4]();
  57. }
  58. }
  59.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.8/chrono:35:0,
                 from prog.cpp:2:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
prog.cpp:6:3: error: ‘chrono’ in namespace ‘std’ does not name a type
   std::chrono::high_resolution_clock::time_point beg, duration;
   ^
prog.cpp: In constructor ‘Duration::Duration()’:
prog.cpp:9:5: error: ‘beg’ was not declared in this scope
     beg = std::chrono::high_resolution_clock::now();
     ^
prog.cpp:9:16: error: ‘std::chrono’ has not been declared
     beg = std::chrono::high_resolution_clock::now();
                ^
prog.cpp: In destructor ‘Duration::~Duration()’:
prog.cpp:12:5: error: ‘duration’ was not declared in this scope
     duration = std::chrono::high_resolution_clock::now();
     ^
prog.cpp:12:21: error: ‘std::chrono’ has not been declared
     duration = std::chrono::high_resolution_clock::now();
                     ^
prog.cpp:13:23: error: ‘std::chrono’ has not been declared
     std::cout << std::chrono::duration_cast<std::chrono::microseconds>(duration - beg).count() / 1000 << "ms" << std::endl;
                       ^
prog.cpp:13:50: error: ‘std::chrono’ has not been declared
     std::cout << std::chrono::duration_cast<std::chrono::microseconds>(duration - beg).count() / 1000 << "ms" << std::endl;
                                                  ^
prog.cpp:13:83: error: ‘beg’ was not declared in this scope
     std::cout << std::chrono::duration_cast<std::chrono::microseconds>(duration - beg).count() / 1000 << "ms" << std::endl;
                                                                                   ^
stdout
Standard output is empty