Advertisement
Guest User

Untitled

a guest
Jul 11th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. #include <windows.h>
  5.  
  6. class A {
  7. private:
  8.     std::string foo;
  9. public:
  10.     std::string& getFoo()
  11.     {
  12.         return foo;
  13.     }
  14.     void setString(std::string & In_foo)
  15.     {
  16.         foo = In_foo;
  17.     }
  18. };
  19. class B {
  20. public:
  21.     std::string foo;
  22. };
  23.  
  24. int main() {
  25.  
  26.     LONGLONG g_Frequency, g_CurentCount, g_LastCount;
  27.     QueryPerformanceFrequency((LARGE_INTEGER*)&g_Frequency);
  28.  
  29.     std::cout << "With setters" << std::endl;
  30.  
  31.     A a;
  32.     for(int j = 0; j < 10; j++)
  33.     {
  34.         std::string rover("rover");
  35.         QueryPerformanceCounter((LARGE_INTEGER*)&g_CurentCount);
  36.         for(int i = 0; i < 10000000; i++)
  37.         {
  38.             a.setString(rover);
  39.             std::string foo = a.getFoo();
  40.         }
  41.  
  42.         QueryPerformanceCounter((LARGE_INTEGER*)&g_LastCount);
  43.  
  44.         double dTimeDiff = (((double)(g_LastCount-g_CurentCount))/((double)g_Frequency));  
  45.  
  46.         std::cout << dTimeDiff << std::endl;
  47.     }
  48.  
  49.  
  50.     std::cout << std::endl << "Without setters" << std::endl;
  51.     B b;
  52.     for(int j = 0; j < 10; j++)
  53.     {
  54.         std::string rover("rover");
  55.         QueryPerformanceCounter((LARGE_INTEGER*)&g_CurentCount);
  56.         for(int i = 0; i < 10000000; i++)
  57.         {
  58.             b.foo = rover;
  59.             std::string foo = b.foo;
  60.         }
  61.         QueryPerformanceCounter((LARGE_INTEGER*)&g_LastCount);
  62.  
  63.         double dTimeDiff = (((double)(g_LastCount-g_CurentCount))/((double)g_Frequency));  
  64.  
  65.         std::cout << dTimeDiff << std::endl;
  66.     }
  67.     system("PAUSE");
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement