Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <windows.h>
- class A {
- private:
- std::string foo;
- public:
- std::string& getFoo()
- {
- return foo;
- }
- void setString(std::string & In_foo)
- {
- foo = In_foo;
- }
- };
- class B {
- public:
- std::string foo;
- };
- int main() {
- LONGLONG g_Frequency, g_CurentCount, g_LastCount;
- QueryPerformanceFrequency((LARGE_INTEGER*)&g_Frequency);
- std::cout << "With setters" << std::endl;
- A a;
- for(int j = 0; j < 10; j++)
- {
- std::string rover("rover");
- QueryPerformanceCounter((LARGE_INTEGER*)&g_CurentCount);
- for(int i = 0; i < 10000000; i++)
- {
- a.setString(rover);
- std::string foo = a.getFoo();
- }
- QueryPerformanceCounter((LARGE_INTEGER*)&g_LastCount);
- double dTimeDiff = (((double)(g_LastCount-g_CurentCount))/((double)g_Frequency));
- std::cout << dTimeDiff << std::endl;
- }
- std::cout << std::endl << "Without setters" << std::endl;
- B b;
- for(int j = 0; j < 10; j++)
- {
- std::string rover("rover");
- QueryPerformanceCounter((LARGE_INTEGER*)&g_CurentCount);
- for(int i = 0; i < 10000000; i++)
- {
- b.foo = rover;
- std::string foo = b.foo;
- }
- QueryPerformanceCounter((LARGE_INTEGER*)&g_LastCount);
- double dTimeDiff = (((double)(g_LastCount-g_CurentCount))/((double)g_Frequency));
- std::cout << dTimeDiff << std::endl;
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement