-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
49 lines (41 loc) · 1.77 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <chrono>
#include <iostream>
#include <string>
#include "InterfaceVersion1.h"
#include "InterfaceVersion2.h"
#include "InterfaceVersion3.h"
#include "InterfaceVersion3b.h"
#include "InterfaceVersion3c.h"
#include "InterfaceVersion4.h"
#include "InterfaceVersion4b.h"
template <typename T>
void Test(const std::string& title, T&& testObject)
{
const std::clock_t startTime = std::clock();
volatile long result = 0;
for (unsigned long i = 0; i < 1'000'000'000; ++i)
{
result += testObject->read();
}
const std::clock_t endTime = std::clock();
std::cout << "Execution time of " << title << " : " << 1000 * (endTime - startTime) / CLOCKS_PER_SEC
<< " ms" << std::endl;
}
int main()
{
std::shared_ptr<BasePublicVirtual> basePublicVirtual = std::make_shared<ChildPublicVirtual>();
std::shared_ptr<BasePrivateVirtual> basePrivateVirtual = std::make_shared<ChildPrivateVirtual>();
std::shared_ptr<BaseChildCrtp> baseCrtp = std::make_shared<BaseChildCrtp>();
std::shared_ptr<BaseTemplateT> baseTemplate = std::make_shared<BaseTemplateT>();
std::shared_ptr<BaseTemplate2T> baseTemplate2 = std::make_shared<BaseTemplate2T>();
std::shared_ptr<BaseLambda> baseLambda = std::make_shared<ChildLambda>();
std::shared_ptr<BaseLambdaT> baseLambdaTemplate = std::make_shared<BaseLambdaT>();
Test("C++ Interface with virtual public method", basePublicVirtual);
Test("C++ Interface with virtual private method", basePrivateVirtual);
Test("C++ Interface with CRTP", baseCrtp);
Test("C++ Interface with Template", baseTemplate);
Test("C++ Interface with Template 2", baseTemplate2);
Test("C++ Interface with Lambda", baseLambda);
Test("C++ Interface with Lambda and Template", baseLambdaTemplate);
return 0;
}