Guest User

Untitled

a guest
Aug 4th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. using namespace std;
  4. using namespace std::chrono;
  5.  
  6. int main() {
  7.     int intNumber = 32;
  8.     double floatNumber = 32;
  9.  
  10.     microseconds ms = duration_cast<microseconds>(system_clock::now().time_since_epoch());
  11.     for (long int i = 0; i < 1000000000; i++)
  12.         int num = static_cast<int>(floatNumber) >> 3;
  13.     cout << "Bitshift time on float: " << (duration_cast<microseconds>(system_clock::now().time_since_epoch()) - ms).count() << endl;
  14.  
  15.     ms = duration_cast<microseconds>(system_clock::now().time_since_epoch());
  16.     for (long int i = 0; i < 1000000000; i++)
  17.         int num = floatNumber / 8;
  18.     cout << "Div time on float     : " << (duration_cast<microseconds>(system_clock::now().time_since_epoch()) - ms).count() << endl;
  19.  
  20.     ms = duration_cast<microseconds>(system_clock::now().time_since_epoch());
  21.     for (long int i = 0; i < 1000000000; i++)
  22.         int num = intNumber >> 3;
  23.     cout << "Bitshift time on int  : " << (duration_cast<microseconds>(system_clock::now().time_since_epoch()) - ms).count() << endl;
  24.  
  25.     ms = duration_cast<microseconds>(system_clock::now().time_since_epoch());
  26.     for (long int i = 0; i < 1000000000; i++)
  27.         int num = intNumber / 8;
  28.     cout << "Div time on int       : " << (duration_cast<microseconds>(system_clock::now().time_since_epoch()) - ms).count() << endl;
  29.  
  30.     system("PAUSE");
  31.     return 0;
  32. }
Add Comment
Please, Sign In to add comment