Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <chrono>
  4.  
  5. using namespace std;
  6. using namespace std::chrono;
  7.  
  8. class Test {
  9. public:
  10.     int x;
  11.     float y;
  12. };
  13.  
  14. inline float test1(int x, float y) {
  15.     return x + y;
  16. }
  17.  
  18. float test2(int x, float y) {
  19.     return x + y;
  20. }
  21.  
  22. inline float test3(Test* test) {
  23.     return test->x + test->y;
  24. }
  25.  
  26. float test4(Test* test) {
  27.     return test->x + test->y;
  28. }
  29.  
  30. inline float test5(Test test) {
  31.     return test.x + test.y;
  32. }
  33.  
  34. float test6(Test test) {
  35.     return test.x + test.y;
  36. }
  37.  
  38. float test7(Test &test) {
  39.     return test.x + test.y;
  40. }
  41.  
  42. int test8(int x) {
  43.     int a = 52;
  44.     float b = 798.5;
  45.     bool c = true;
  46.  
  47.     if (x == 0) {
  48.         return 0;
  49.     }
  50.  
  51.     return test8(x - 1) + 1;
  52. }
  53.  
  54.  
  55. int main() {
  56.     high_resolution_clock::time_point roundStart = high_resolution_clock::now();
  57.  
  58.     vector<Test*> vector1;
  59.     vector<Test> vector2(100000);
  60.  
  61.     for (int i = 0; i < 100000; ++i) {
  62.         vector1.push_back(new Test());
  63.     }
  64.  
  65.     for (int i = 0; i < 100000; ++i) {
  66.         test1(10, 50.5);
  67.         test2(10, 50.5);
  68.         test3(vector1[i]);
  69.         test4(vector1[i]);
  70.         test5(vector2[i]);
  71.         test6(vector2[i]);
  72.         test7(vector2[i]);
  73.         test8(500);
  74.     }
  75.  
  76.     high_resolution_clock::time_point end = high_resolution_clock::now();
  77.     duration<double> time_span = duration_cast<duration<double>>(end - roundStart);
  78.  
  79.     cout << (time_span.count() * 1000) << "ms" << endl;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement