Skip to content

Commit 518ce41

Browse files
committed
Improved ExperimentValue. Bug Fixes.
Breaking changes due to type of value being passed for ExperimentValue (object to pointer).
1 parent 6646a8f commit 518ce41

27 files changed

+283
-209
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pip-log.txt
174174
*.png
175175
*.xcf
176176
[Bb]uild/
177+
[Bb]uildLinux/
177178

178179
#############
179180
## CMake

CMakeLists.txt

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,44 @@
2121
# Cmake Configuration
2222
#
2323

24-
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2)
24+
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
25+
cmake_policy(SET CMP0128 NEW)
26+
27+
enable_language(CXX)
28+
29+
include(CheckFunctionExists)
30+
include(CheckCXXSourceCompiles)
31+
include(CheckIncludeFile)
32+
include(GenerateExportHeader)
33+
include(CMakePackageConfigHelpers)
34+
35+
#
36+
# User Options
37+
#
38+
39+
option(CELERO_COMPILE_DYNAMIC_LIBRARIES "Set to ON to build Celero for dynamic linking. Use OFF for static." ON)
40+
option(CELERO_COMPILE_PIC "Set to ON to build Celero as a position-independent library." ON)
41+
option(CELERO_ENABLE_EXPERIMENTS "Set to ON to automatically build all examples." OFF)
42+
option(CELERO_ENABLE_FOLDERS "Enable to put Celero in its own solution folder under Visual Studio" ON)
43+
option(CELERO_ENABLE_TESTS "Enable building and running unit tests." OFF)
44+
option(CELERO_ENABLE_WARNINGS_AS_ERRORS "Treat compile warnings as errors." ON)
45+
option(CELERO_ENABLE_CLANG_TIDY_CHECKS "Compile with clang-tidy checks." OFF)
46+
option(CELERO_ENABLE_CLANG_ADDRESS_SANITIZER "Enable the Clang Address Sanitizer" OFF)
47+
48+
#
49+
# Project configuration macro
50+
#
2551

2652
macro(CeleroSetDefaultCompilerOptions)
53+
message(STATUS "Celero: Setting default compiler options for ${PROJECT_NAME}")
54+
2755
set_target_properties(${PROJECT_NAME} PROPERTIES
2856
POSITION_INDEPENDENT_CODE "${CELERO_COMPILE_PIC}"
2957
)
3058

31-
if(CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
59+
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
60+
message(STATUS "Celero: Configuring Visual Studio for ${PROJECT_NAME}")
61+
3262
target_compile_options(${PROJECT_NAME} PRIVATE /D_VARIADIC_MAX=10 )
3363
target_compile_options(${PROJECT_NAME} PRIVATE /D_CRT_SECURE_NO_WARNINGS)
3464
target_compile_options(${PROJECT_NAME} PRIVATE /wd4251)
@@ -48,33 +78,65 @@ macro(CeleroSetDefaultCompilerOptions)
4878
endif()
4979
endif()
5080

51-
if(CELERO_TREAT_WARNINGS_AS_ERRORS)
81+
if(CELERO_ENABLE_WARNINGS_AS_ERRORS)
5282
target_compile_options(${PROJECT_NAME} PRIVATE /WX)
5383
endif()
5484

55-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
85+
if(CELERO_ENABLE_CLANG_TIDY_CHECKS)
86+
message(STATUS "Celero: Enabling Clang-Tidy checks for ${PROJECT_NAME}")
87+
set_target_properties(${PROJECT_NAME} PROPERTIES
88+
VS_GLOBAL_RunCodeAnalysis true
89+
90+
# Use visual studio core guidelines
91+
# VS_GLOBAL_EnableMicrosoftCodeAnalysis true
92+
93+
# Use clangtidy
94+
VS_GLOBAL_EnableClangTidyCodeAnalysis true
95+
VS_GLOBAL_ClangTidyChecks -*,modernize-*,boost-*,bugprone-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,hicpp-*misc-*,modernize-*,performance-*,portability-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters
96+
)
97+
endif()
98+
99+
if(CELERO_ENABLE_CLANG_ADDRESS_SANITIZER)
100+
message(STATUS "Celero: Enabling Clang Address Sanitizer (ASAN) for the Release configuration of ${PROJECT_NAME}")
101+
target_compile_options(${PROJECT_NAME} PRIVATE
102+
$<$<CONFIG:Release>:-fsanitize=address /Zi>
103+
)
104+
105+
target_link_libraries(${PROJECT_NAME} PUBLIC
106+
$<$<CONFIG:Release>:clang_rt.asan_dynamic-x86_64>
107+
$<$<CONFIG:Release>:clang_rt.asan_dynamic_runtime_thunk-x86_64>
108+
)
109+
endif()
110+
111+
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
112+
message(STATUS "Celero: Configuring GCC for ${PROJECT_NAME}")
113+
56114
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
57115

58-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
116+
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
117+
message(STATUS "Celero: Configuring Clang for ${PROJECT_NAME}")
118+
59119
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
60120
target_compile_options(${PROJECT_NAME} PRIVATE -Xclang)
61121
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-c++98-compat)
62122
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-c++98-compat-pedantic)
63123
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-reserved-id-macro)
64-
if(CELERO_TREAT_WARNINGS_AS_ERRORS)
124+
if(CELERO_ENABLE_WARNINGS_AS_ERRORS)
65125
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
66126
endif()
67127
else()
68128
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
69-
if(CELERO_TREAT_WARNINGS_AS_ERRORS)
129+
if(CELERO_ENABLE_WARNINGS_AS_ERRORS)
70130
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
71131
endif()
72132
endif()
73133

74-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
134+
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
135+
message(STATUS "Celero: Configuring Apple Clang for ${PROJECT_NAME}")
136+
75137
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
76138

77-
if(CELERO_TREAT_WARNINGS_AS_ERRORS)
139+
if(CELERO_ENABLE_WARNINGS_AS_ERRORS)
78140
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
79141
endif()
80142
endif()
@@ -90,17 +152,6 @@ include(CMakePackageConfigHelpers)
90152
include(GNUInstallDirs)
91153
include(CMakeFindDependencyMacro)
92154

93-
#
94-
# User Options
95-
#
96-
97-
option(CELERO_COMPILE_DYNAMIC_LIBRARIES "Set to ON to build Celero for dynamic linking. Use OFF for static." ON)
98-
option(CELERO_COMPILE_PIC "Set to ON to build Celero as a position-independent library." ON)
99-
option(CELERO_ENABLE_EXPERIMENTS "Set to ON to automatically build all examples." OFF)
100-
option(CELERO_ENABLE_FOLDERS "Enable to put Celero in its own solution folder under Visual Studio" ON)
101-
option(CELERO_ENABLE_TESTS "Enable building and running unit tests." OFF)
102-
option(CELERO_TREAT_WARNINGS_AS_ERRORS "Treat compile warnings as errors." ON)
103-
104155
if(CELERO_COMPILE_DYNAMIC_LIBRARIES)
105156
SET(CELERO_USER_DEFINED_SHARED_OR_STATIC "SHARED")
106157
else()
@@ -190,6 +241,7 @@ target_sources(${PROJECT_NAME} PRIVATE
190241
src/Timer.cpp
191242
src/UserDefinedMeasurementCollector.cpp
192243
src/Utilities.cpp
244+
README.md
193245
)
194246

195247
if(WIN32)

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,16 @@ A Special Thanks to the following corporations for their support:
1414
- [Araxis](https://www.araxis.com/)
1515
- [Axosoft](https://www.gitkraken.com/)
1616
- [Microsoft](https://www.microsoft.com)
17-
- [Travis.CI](https://travis-ci.org)
1817

1918
#### Builds and Testing
2019

21-
| Branch | Status |
22-
|:-----------------------|:---------------------------------------------------------------------------------------------------------------------------------------|
23-
| ```origin/master: ``` | [![Build Status (Master)](https://travis-ci.org/DigitalInBlue/Celero.svg?branch=master)](https://travis-ci.org/DigitalInBlue/Celero) |
24-
| ```origin/develop: ``` | [![Build Status (Develop)](https://travis-ci.org/DigitalInBlue/Celero.svg?branch=develop)](https://travis-ci.org/DigitalInBlue/Celero) |
25-
26-
Celero has been successfully built on the following platforms during development. See [Travis.CI](https://travis-ci.org/DigitalInBlue/Celero) for more details.
20+
Celero has been successfully built on the following platforms during development.
2721

2822
- GCC v6.0.0
2923
- GCC v7.0.0
3024
- GCC v8.0.0
3125
- GCC v9.0.0
26+
- GCC v9.4.0
3227
- LLVM v3.9.0
3328
- LLVM v5.0.1
3429
- LLVM v7.0.0
@@ -38,6 +33,7 @@ Celero has been successfully built on the following platforms during development
3833
- Visual Studio 2019 (16.11.5)
3934
- Visual Studio 2022 (17.0.5)
4035
- Visual Studio 2022 (17.4.3)
36+
- Visual Studio 2022 (17.5.5)
4137
- XCode v10.1
4238
- XCode v10.3
4339
- XCode v11.0
@@ -56,13 +52,13 @@ As of v2.7, Celero requres the developer to provide GoogleTest in order to build
5652

5753
Developing consistent and meaningful benchmark results for code is a complicated task. Measurement tools exist (Intel® VTune™ Amplifier, SmartBear AQTime, Valgrind, etc.) external to applications, but they are sometimes expensive for small teams or cumbersome to utilize. This project, Celero, aims to be a small library which can be added to a C++ project and perform benchmarks on code in a way which is easy to reproduce, share, and compare among individual runs, developers, or projects. Celero uses a framework similar to that of GoogleTest to make its API more natural to use and integrate into a project. Make automated benchmarking as much a part of your development process as automated testing.
5854

59-
Celero uses CMake to provide cross-platform builds. It does require a modern compiler (Visual C++ 2012+, GCC 4.7+, Clang 2.9+) due to its use of C++11.
55+
Celero uses CMake to provide cross-platform builds. It does require a modern compiler (Visual C++ 2012+, GCC 4.7+, Clang 2.9+) due to its use of C++14.
6056

6157
Once Celero is added to your project. You can create dedicated benchmark projects and source files. For convenience, there is single header file and a `CELERO_MAIN` macro that can be used to provide a `main()` for your benchmark project that will automatically execute all of your benchmark tests.
6258

6359
### Key Features
6460

65-
- Supports Windows, Linux, and OSX using C++11.
61+
- Supports Windows, Linux, and OSX using C++14.
6662
- The timing utilities can be used directly in production code (independent of benchmarks).
6763
- Automatically tracks RAM usage during the experiments
6864
- Console table output is formatted as Markdown to easily copy/paste into documents.

experiments/DemoFileWrite/DemoFileWrite.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ CELERO_MAIN
55
class BaseFixture : public celero::TestFixture
66
{
77
public:
8-
std::vector<celero::TestFixture::ExperimentValue> getExperimentValues() const override
8+
std::vector<std::shared_ptr<celero::TestFixture::ExperimentValue>> getExperimentValues() const override
99
{
10-
std::vector<celero::TestFixture::ExperimentValue> bufferSizes;
11-
bufferSizes.push_back(32);
12-
bufferSizes.push_back(64);
13-
bufferSizes.push_back(128);
14-
bufferSizes.push_back(256);
15-
bufferSizes.push_back(512);
16-
bufferSizes.push_back(1024);
17-
bufferSizes.push_back(2048);
18-
bufferSizes.push_back(4096);
10+
std::vector<std::shared_ptr<celero::TestFixture::ExperimentValue>> bufferSizes;
11+
bufferSizes.push_back(std::make_shared<celero::TestFixture::ExperimentValue>(32));
12+
bufferSizes.push_back(std::make_shared<celero::TestFixture::ExperimentValue>(64));
13+
bufferSizes.push_back(std::make_shared<celero::TestFixture::ExperimentValue>(128));
14+
bufferSizes.push_back(std::make_shared<celero::TestFixture::ExperimentValue>(256));
15+
bufferSizes.push_back(std::make_shared<celero::TestFixture::ExperimentValue>(512));
16+
bufferSizes.push_back(std::make_shared<celero::TestFixture::ExperimentValue>(1024));
17+
bufferSizes.push_back(std::make_shared<celero::TestFixture::ExperimentValue>(2048));
18+
bufferSizes.push_back(std::make_shared<celero::TestFixture::ExperimentValue>(4096));
1919
return bufferSizes;
2020
}
2121

@@ -25,11 +25,11 @@ class BaseFixture : public celero::TestFixture
2525
return 1024.0 * 1024.0;
2626
}
2727

28-
void setUp(const celero::TestFixture::ExperimentValue& experimentValue) override
28+
void setUp(const celero::TestFixture::ExperimentValue* const experimentValue) override
2929
{
30-
for(auto i = 0; i < experimentValue.Value; ++i)
30+
for(auto i = 0; i < experimentValue->Value; ++i)
3131
{
32-
this->buffer.push_back(celero::Random() % 256);
32+
this->buffer.push_back(std::abs(celero::Random()) % 256);
3333
}
3434
}
3535

@@ -44,10 +44,15 @@ class BaseFixture : public celero::TestFixture
4444
class StdFileFixture : public BaseFixture
4545
{
4646
public:
47-
void setUp(const celero::TestFixture::ExperimentValue& x) override
47+
void setUp(const celero::TestFixture::ExperimentValue* const x) override
4848
{
4949
BaseFixture::setUp(x);
50+
51+
#ifdef WIN32
5052
fopen_s(&this->file , "FileWrite.out", "wb");
53+
#else
54+
this->file = fopen("FileWrite.out", "wb");
55+
#endif
5156
}
5257

5358
void tearDown() override

experiments/DemoMultithread/DemoMultithread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class BaseFixture : public celero::ThreadTestFixture
1010
public:
1111
int counter;
1212

13-
void setUp(const celero::TestFixture::ExperimentValue&) override
13+
void setUp(const celero::TestFixture::ExperimentValue* const) override
1414
{
1515
this->counter = 0;
1616
}
@@ -21,7 +21,7 @@ class AtomicFixture : public celero::ThreadTestFixture
2121
public:
2222
std::atomic<int> counter;
2323

24-
void setUp(const celero::TestFixture::ExperimentValue&) override
24+
void setUp(const celero::TestFixture::ExperimentValue* const) override
2525
{
2626
this->counter = 0;
2727
}
@@ -33,7 +33,7 @@ class MutexFixture : public celero::ThreadTestFixture
3333
int counter;
3434
std::mutex mutex;
3535

36-
void setUp(const celero::TestFixture::ExperimentValue&) override
36+
void setUp(const celero::TestFixture::ExperimentValue* const) override
3737
{
3838
this->counter = 0;
3939
}

experiments/DemoTransform/DemoTransform.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class DemoTransformFixture : public celero::TestFixture
4545
{
4646
}
4747

48-
std::vector<celero::TestFixture::ExperimentValue> getExperimentValues() const override
48+
std::vector<std::shared_ptr<celero::TestFixture::ExperimentValue>> getExperimentValues() const override
4949
{
50-
std::vector<celero::TestFixture::ExperimentValue> problemSpaceValues;
50+
std::vector<std::shared_ptr<celero::TestFixture::ExperimentValue>> problemSpaceValues;
5151

5252
// We will run some total number of sets of tests all together.
5353
// Each one growing by a power of 2.
@@ -60,16 +60,17 @@ class DemoTransformFixture : public celero::TestFixture
6060
// We make the number of iterations decrease as the size of our problem space increases
6161
// to demonstrate how to adjust the number of iterations per sample based on the
6262
// problem space size.
63-
problemSpaceValues.push_back({int64_t(pow(2, i + 1)), int64_t(pow(2, totalNumberOfTests - i))});
63+
problemSpaceValues.push_back(
64+
std::make_shared<celero::TestFixture::ExperimentValue>(int64_t(pow(2, i + 1)), int64_t(pow(2, totalNumberOfTests - i))));
6465
}
6566

6667
return problemSpaceValues;
6768
}
6869

6970
/// Before each run, build a vector of random integers.
70-
void setUp(const celero::TestFixture::ExperimentValue& experimentValue) override
71+
void setUp(const celero::TestFixture::ExperimentValue* const experimentValue) override
7172
{
72-
this->arraySize = static_cast<int>(experimentValue.Value);
73+
this->arraySize = static_cast<int>(experimentValue->Value);
7374

7475
for(int i = 0; i < this->arraySize; i++)
7576
{

0 commit comments

Comments
 (0)