fork(1) download
  1. #include <cstring>
  2. #include <ctime>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. struct Frame
  7. {
  8. Frame()
  9. : start(std::clock())
  10. {
  11. }
  12.  
  13. ~Frame()
  14. {
  15. clocks += std::clock() - start;
  16. ++frames;
  17. }
  18.  
  19. static double GetTime()
  20. {
  21. if (!frames)
  22. return 0;
  23.  
  24. return clocks * 1000.0 / CLOCKS_PER_SEC / frames;
  25. }
  26.  
  27. std::clock_t start;
  28. static std::clock_t clocks;
  29. static std::uint64_t frames;
  30. };
  31.  
  32. std::clock_t Frame::clocks;
  33. std::uint64_t Frame::frames;
  34.  
  35. #define FRAME_START() { Frame __frame;
  36. #define FRAME_STOP() }
  37.  
  38. int main()
  39. {
  40. const int size = 1024*1024;
  41. std::vector<int> a(size), b(size);
  42.  
  43. for (int k = 0; k < 1000; ++k) {
  44. FRAME_START()
  45. int *pa = a.data();
  46. int *pb = b.data();
  47. for (int i = 0; i < 1024; ++i) {
  48. #if 1
  49. std::memcpy(pa, pb, 1024 * 4);
  50. pa += 1024;
  51. pb += 1024;
  52. #else
  53. for (int j = 0; j < 1024; ++j)
  54. *pa++ = *pb++;
  55. #endif
  56. }
  57. FRAME_STOP()
  58. }
  59.  
  60. std::cout << "Frame time: "<< Frame::GetTime() << "\n";
  61. }
Success #stdin #stdout 0.32s 15232KB
stdin
Standard input is empty
stdout
Frame time: 0.323903