Last active
January 21, 2019 02:37
-
-
Save cleak/b7fb2f900ff6d3f5ab09c058724b2b3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IncrementerBase { | |
public: | |
IncrementerBase() { | |
my_num = rand(); | |
} | |
virtual ~IncrementerBase() {} | |
virtual void Increment() {} | |
int my_num; | |
}; | |
class IncrementerVirtual : public IncrementerBase { | |
public: | |
IncrementerVirtual() { } | |
virtual ~IncrementerVirtual() {} | |
virtual void Increment() override { | |
g_update_count += my_num; | |
} | |
}; | |
class IncrementerDirect : public IncrementerBase { | |
public: | |
IncrementerDirect() {} | |
virtual ~IncrementerDirect() {} | |
// Preventing inling to force a fair comparison. | |
__declspec(noinline) void IncrementDirect() { | |
g_update_count += my_num; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment