Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <chrono>
  3. #include <ctime>
  4.  
  5. #define MAX 1000000
  6.  
  7. double *g_h = nullptr;
  8. void bench() {
  9. double temp_double = 0.0;
  10. for (int i = 0; i < MAX; i++) {
  11. g_h[i] = 1.0;
  12. temp_double = g_h[i];
  13. }
  14.  
  15. }
  16.  
  17. int main() {
  18. g_h = new double[MAX];
  19.  
  20. std::chrono::duration<double> elapsed_seconds(0.0);
  21. std::chrono::time_point<std::chrono::system_clock> start, end;
  22.  
  23. start = std::chrono::system_clock::now();
  24. for (int i = 0; i < 20000; i++) {
  25. bench();
  26. }
  27.  
  28. end = std::chrono::system_clock::now();
  29.  
  30. elapsed_seconds = end-start;
  31.  
  32.  
  33. printf("Total elapsed time: %e. Average time: %e\n", elapsed_seconds.count(), elapsed_seconds.count()/200);
  34.  
  35. delete [] g_h;
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement