Commit daa8a67a by Eric Fiselier

add C++03 test and update README

parent 38066e8b
...@@ -27,9 +27,9 @@ include(CXXFeatureCheck) ...@@ -27,9 +27,9 @@ include(CXXFeatureCheck)
check_cxx_compiler_flag(-std=c++11 HAVE_FLAG_CXX_11) check_cxx_compiler_flag(-std=c++11 HAVE_FLAG_CXX_11)
check_cxx_compiler_flag(-std=c++0x HAVE_FLAG_CXX_0X) check_cxx_compiler_flag(-std=c++0x HAVE_FLAG_CXX_0X)
if (HAVE_FLAG_CXX_11) if (HAVE_FLAG_CXX_11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") list(APPEND CMAKE_CXX_FLAGS -std=c++11)
elseif (HAVE_FLAG_CXX_0X) elseif (HAVE_FLAG_CXX_0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") list(APPEND CMAKE_CXX_FLAGS -std=c++0x)
endif() endif()
# Turn compiler warnings up to 11 # Turn compiler warnings up to 11
......
...@@ -130,6 +130,18 @@ template <class Q> int BM_Sequential(benchmark::State& state) { ...@@ -130,6 +130,18 @@ template <class Q> int BM_Sequential(benchmark::State& state) {
BENCHMARK_TEMPLATE(BM_Sequential, WaitQueue<int>)->Range(1<<0, 1<<10); BENCHMARK_TEMPLATE(BM_Sequential, WaitQueue<int>)->Range(1<<0, 1<<10);
``` ```
Three macros are provided for adding benchmark templates.
```c++
#if __cplusplus >= 201103L // C++11 and greater.
#define BENCHMARK_TEMPLATE(func, ...) // Takes any number of parameters.
#else // C++ < C++11
#define BENCHMARK_TEMPLATE(func, arg1)
#endif
#define BENCHMARK_TEMPLATE1(func, arg1)
#define BENCHMARK_TEMPLATE2(func, arg1, arg2)
```
In a multithreaded test, it is guaranteed that none of the threads will start In a multithreaded test, it is guaranteed that none of the threads will start
until all have called KeepRunning, and all will have finished before KeepRunning until all have called KeepRunning, and all will have finished before KeepRunning
returns false. As such, any global setup or teardown you want to do can be returns false. As such, any global setup or teardown you want to do can be
......
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
set(CXX03_FLAGS "${CMAKE_CXX_FLAGS}")
list(REMOVE_ITEM CXX03_FLAGS -std=c++11 -std=c++0x)
list(APPEND CXX03_FLAGS -std=c++03)
string(REPLACE ";" " " CXX03_FLAGS "${CXX03_FLAGS}")
macro(compile_benchmark_test name) macro(compile_benchmark_test name)
add_executable(${name} "${name}.cc") add_executable(${name} "${name}.cc")
target_link_libraries(${name} benchmark ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(${name} benchmark ${CMAKE_THREAD_LIBS_INIT})
...@@ -23,3 +28,8 @@ add_test(filter_regex_end filter_test --benchmark_filter=.*Pi$ 8) ...@@ -23,3 +28,8 @@ add_test(filter_regex_end filter_test --benchmark_filter=.*Pi$ 8)
compile_benchmark_test(basic_test) compile_benchmark_test(basic_test)
add_test(basic basic_test) add_test(basic basic_test)
compile_benchmark_test(cxx03_test)
set_target_properties(cxx03_test
PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
add_test(cxx03 cxx03_test)
...@@ -121,6 +121,10 @@ static void BM_Sequential(benchmark::State& state) { ...@@ -121,6 +121,10 @@ static void BM_Sequential(benchmark::State& state) {
} }
BENCHMARK_TEMPLATE2(BM_Sequential, std::vector<int>, int)->Range(1 << 0, 1 << 10); BENCHMARK_TEMPLATE2(BM_Sequential, std::vector<int>, int)->Range(1 << 0, 1 << 10);
BENCHMARK_TEMPLATE(BM_Sequential, std::list<int>)->Range(1 << 0, 1 << 10); BENCHMARK_TEMPLATE(BM_Sequential, std::list<int>)->Range(1 << 0, 1 << 10);
// Test the variadic version of BENCHMARK_TEMPLATE in C++11 and beyond.
#if __cplusplus >= 201103L
BENCHMARK_TEMPLATE(BM_Sequential, std::vector<int>, int)->Arg(512);
#endif
static void BM_StringCompare(benchmark::State& state) { static void BM_StringCompare(benchmark::State& state) {
std::string s1(state.range_x(), '-'); std::string s1(state.range_x(), '-');
......
#include <cstddef>
#include "benchmark/benchmark.h"
#if __cplusplus >= 201103L
#error C++11 or greater detected. Should be C++03.
#endif
void BM_empty(benchmark::State& state) {
while (state.KeepRunning()) {
volatile std::size_t x = state.iterations();
((void)x);
}
}
BENCHMARK(BM_empty);
template <class T, class U>
void BM_template2(benchmark::State& state) {
BM_empty(state);
}
BENCHMARK_TEMPLATE2(BM_template2, int, long);
template <class T>
void BM_template1(benchmark::State& state) {
BM_empty(state);
}
BENCHMARK_TEMPLATE(BM_template1, long);
BENCHMARK_TEMPLATE1(BM_template1, int);
BENCHMARK_MAIN()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment