-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
166 lines (140 loc) · 4.86 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
#if defined(_WIN32) || defined(_WIN64)
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#include <dlfcn.h>
#elif defined(__linux__)
#include <link.h>
#include <dlfcn.h>
#endif
#include <NoiseBenchmarkInterface.h>
void LoadDynamicLibs()
{
fs::path directory( "." );
std::string libExtension;
std::string libPrefix = "Bench";
#if defined(_WIN32) || defined(_WIN64)
libExtension = ".dll";
#elif defined(__APPLE__)
libExtension = ".dylib";
#elif defined( __linux__)
libExtension = ".so";
#else
static_assert(false);
#endif
fs::directory_iterator iter( directory );
fs::directory_iterator endIter;
while( iter != endIter )
{
fs::path filePath = iter->path();
std::string fileName = filePath.stem().string();
std::string extension = filePath.extension().string();
if( fs::is_regular_file( *iter ) && extension == libExtension && fileName.compare( 0, libPrefix.size(), libPrefix.c_str() ) == 0 )
{
#if defined(_WIN32) || defined(_WIN64)
HINSTANCE instance = NULL;
try
{
instance = LoadLibrary( filePath.string().c_str() );
} //Plugins should autoregister
catch( ... )
{
instance = NULL;
}
if( instance == NULL )
{
LPVOID lpMsgBuf;
DWORD error = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error,
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
(LPTSTR)&lpMsgBuf,
0,
NULL
);
std::string message( (char*)lpMsgBuf );
std::cout << "Failed to load " << fileName << " error: " << message;
LocalFree( lpMsgBuf );
}
#elif defined(__APPLE__) || defined( __linux__)
void* handle;
dlerror();
try
{
handle = dlopen( filePath.string().c_str(), RTLD_NOW );
}
catch( std::exception& except )
{
handle = NULL;
}
catch( ... )
{
handle = NULL;
}
if( handle == NULL )
{
char* error = dlerror();
std::cout << "Failed to load " << fileName << " error: " << error;
}
#else
static_assert(false);
#endif
}
++iter;
}
}
int main( int argc, char** argv )
{
benchmark::Initialize( &argc, argv );
if( benchmark::ReportUnrecognizedArguments( argc, argv ) ) { return 1; }
LoadDynamicLibs();
int64_t dimensionSize2D = 512;
int64_t dimensionSize3D = 64;
for( size_t dimensionCount = 2; dimensionCount <= 3; dimensionCount++ )
{
for( auto noiseType = (NoiseBenchmarkInterface::NoiseType)0;
noiseType < NoiseBenchmarkInterface::NoiseType::EnumMax;
noiseType = (NoiseBenchmarkInterface::NoiseType)((int)noiseType + 1) )
{
for( NoiseBenchmarkInterface* noiseBenchmarkInterface : GetRegisteredNoiseBenchmarks() )
{
if( !noiseBenchmarkInterface->IsSupported( noiseType, dimensionCount ) )
{
continue;
}
benchmark::internal::Benchmark* benchmark = nullptr;
std::string benchName = noiseBenchmarkInterface->FormatBenchmarkName( noiseType, dimensionCount );
if( dimensionCount == 2 )
{
benchmark = benchmark::RegisterBenchmark( benchName.c_str(), [noiseBenchmarkInterface, noiseType, dimensionSize2D]( benchmark::State& state )
{
noiseBenchmarkInterface->Benchmark2D( state, noiseType, dimensionSize2D );
} );
}
else if( dimensionCount == 3 )
{
benchmark = benchmark::RegisterBenchmark( benchName.c_str(), [noiseBenchmarkInterface, noiseType, dimensionSize3D]( benchmark::State& state )
{
noiseBenchmarkInterface->Benchmark3D( state, noiseType, dimensionSize3D );
} );
}
if( benchmark )
{
benchmark->DisplayAggregatesOnly()->ReportAggregatesOnly();// ->Repetitions( 5 );
}
}
}
}
benchmark::RunSpecifiedBenchmarks();
std::cout << "Benchmarks Complete!";
getchar();
return 0;
}