Advertisement
Guest User

Untitled

a guest
Jan 26th, 2014
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. void test_int()
  9. {
  10.     int res = 0;
  11.     for( size_t i = 0; i < 30000000; i++ ) {
  12.         res += rand() / (rand() + 1);
  13.     }
  14.     cout << res << endl;
  15. }
  16.  
  17. void test_int64()
  18. {
  19.     __int64 res = 0;
  20.     for( size_t i = 0; i < 30000000; i++ ) {
  21.         res += rand() / (rand() + 1);
  22.     }
  23.     cout << res << endl;
  24. }
  25.  
  26. void test_float()
  27. {
  28.     float res = 0.0f;
  29.     for( size_t i = 0; i < 30000000; i++ ) {
  30.         res += rand() / (rand() + 1);
  31.     }
  32.     cout << res << endl;
  33. }
  34.  
  35. void test_rand()
  36. {
  37.     int res = 0;
  38.     for( size_t i = 0; i < 30000000; i++ ) {
  39.         res += rand() / (rand() + 1);
  40.     }
  41.     cout << res << endl;
  42. }
  43.  
  44. void test_double()
  45. {
  46.     double res = 0.0;
  47.     for( size_t i = 0; i < 30000000; i++ ) {
  48.         res += rand() / (rand() + 1);
  49.     }
  50.     cout << res << endl;
  51. }
  52.  
  53. int main(int argc, char* argv[])
  54. {
  55.     srand( time( NULL ) );
  56.     clock_t start;
  57.  
  58.     start = clock();
  59.     test_rand();
  60.     cout << "Rand: " << clock() - start << " tics" << endl;
  61.  
  62.     start = clock();
  63.     test_int();
  64.     cout << "Int: " << clock() - start << " tics" << endl;
  65.  
  66.     start = clock();
  67.     test_int64();
  68.     cout << "Int64: " << clock() - start << " tics" << endl;
  69.  
  70.     start = clock();
  71.     test_float();
  72.     cout << "Float: " << clock() - start << " tics" << endl;
  73.  
  74.     start = clock();
  75.     test_double();
  76.     cout << "Double: " << clock() - start << " tics" << endl;
  77.     cout << "Press any key to quit." << endl;
  78.     getch();
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement