fork download
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. #define MAX_BUFFER 256
  5. const int whileLoops = 1024 * 1024 * 10;
  6.  
  7. void TracedFunction(int blockSize, int controlRate) {
  8. std::chrono::high_resolution_clock::time_point pStart;
  9. std::chrono::high_resolution_clock::time_point pEnd;
  10.  
  11. double A[MAX_BUFFER];
  12. double B[MAX_BUFFER];
  13. double C[MAX_BUFFER];
  14.  
  15. // same traced function
  16. pStart = std::chrono::high_resolution_clock::now();
  17.  
  18. int whileCounter = 0;
  19. while (whileCounter < whileLoops) {
  20. for (int sampleIndex = 0; sampleIndex < blockSize; sampleIndex++) {
  21. double value = A[sampleIndex] + B[sampleIndex];
  22.  
  23. C[sampleIndex] = value;
  24. }
  25.  
  26. whileCounter++;
  27. }
  28.  
  29. pEnd = std::chrono::high_resolution_clock::now();
  30. std::cout << "execution time: " << std::chrono::duration_cast<std::chrono::milliseconds>(pEnd - pStart).count() << " ms" << " | fake result: " << A[19] << " " << B[90] << " " << C[129] << std::endl;
  31. }
  32.  
  33. class OptimizeProcess
  34. {
  35. public:
  36. std::chrono::high_resolution_clock::time_point pStart;
  37. std::chrono::high_resolution_clock::time_point pEnd;
  38.  
  39. double A[MAX_BUFFER];
  40. double B[MAX_BUFFER];
  41. double C[MAX_BUFFER];
  42.  
  43. OptimizeProcess() { }
  44.  
  45. void TracedFunction(int blockSize, int controlRate) {
  46. // same traced function
  47. pStart = std::chrono::high_resolution_clock::now();
  48.  
  49. int whileCounter = 0;
  50. while (whileCounter < whileLoops) {
  51. for (int sampleIndex = 0; sampleIndex < blockSize; sampleIndex++) {
  52. double value = A[sampleIndex] + B[sampleIndex];
  53.  
  54. C[sampleIndex] = value;
  55. }
  56.  
  57. whileCounter++;
  58. }
  59.  
  60. pEnd = std::chrono::high_resolution_clock::now();
  61. std::cout << "execution time: " << std::chrono::duration_cast<std::chrono::milliseconds>(pEnd - pStart).count() << " ms" << " | fake result: " << A[19] << " " << B[90] << " " << C[129] << std::endl;
  62. }
  63. };
  64.  
  65. int main() {
  66. int blockSize = MAX_BUFFER;
  67. int controlRate = 8;
  68.  
  69. // outside class
  70. TracedFunction(blockSize, controlRate);
  71.  
  72. // within class
  73. OptimizeProcess p1;
  74. p1.TracedFunction(blockSize, controlRate);
  75.  
  76. std::cout << std::endl;
  77. system("pause");
  78.  
  79. return 0;
  80. }
Success #stdin #stdout #stderr 2.89s 15240KB
stdin
Standard input is empty
stdout
execution time: 1458 ms | fake result: 0 0 0
execution time: 1436 ms | fake result: 0 0 8.19596e-318

stderr
sh: 1: pause: not found