Advertisement
rhouland

microseconds for random number

May 16th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <ctime>
  2. #include <chrono>
  3. #include <iostream>
  4. #include <sstream>
  5.  
  6. #define SSTR( x ) static_cast< std::ostringstream & >( \
  7. ( std::ostringstream() << std::dec << x ) ).str()
  8.  
  9. int main()
  10. {
  11.     volatile int i = 0;
  12.     auto start = std::chrono::steady_clock::now();
  13.     while (i < 10000000) {
  14.         ++i;
  15.     }
  16.     auto end = std::chrono::steady_clock::now();
  17.     auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
  18.  
  19. std::cout << std::endl << std::endl;
  20. int nn;
  21. nn=elapsed.count();
  22. std::string s = SSTR( nn );
  23.  
  24. std::cout << " Two random digits : " << s << std::endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement