[Bf-blender-cvs] [61f9b3e991c] temp-lib-google-benchmark: First benchmark test.
Jeroen Bakker
noreply at git.blender.org
Wed May 26 12:55:59 CEST 2021
Commit: 61f9b3e991cb56b60cad89841c25d4d937e8c86e
Author: Jeroen Bakker
Date: Wed May 26 12:12:52 2021 +0200
Branches: temp-lib-google-benchmark
https://developer.blender.org/rB61f9b3e991cb56b60cad89841c25d4d937e8c86e
First benchmark test.
===================================================================
M CMakeLists.txt
M extern/CMakeLists.txt
M tests/CMakeLists.txt
A tests/gbenchmark/CMakeLists.txt
A tests/gbenchmark/gbenchmark_test.cc
===================================================================
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f315fa87236..4ac9abf2246 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -472,6 +472,7 @@ endif()
# Unit testsing
option(WITH_GTESTS "Enable GTest unit testing" OFF)
+option(WITH_BENCHMARK_TESTS "Enable Benchmark unit tests" OFF)
option(WITH_OPENGL_RENDER_TESTS "Enable OpenGL render related unit testing (Experimental)" OFF)
option(WITH_OPENGL_DRAW_TESTS "Enable OpenGL UI drawing related unit testing (Experimental)" OFF)
set(TEST_PYTHON_EXE "" CACHE PATH "Python executable to run unit tests")
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 824b2fb0e9c..b5d59e01b0b 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -92,6 +92,10 @@ if(WITH_GTESTS)
add_subdirectory(gmock)
endif()
+if (WITH_BENCHMARK_TESTS)
+ add_subdirectory(gbenchmark)
+endif()
+
if(WITH_SDL AND WITH_SDL_DYNLOAD)
add_subdirectory(sdlew)
endif()
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3d9201bec04..6ba8f6f3b16 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -58,3 +58,6 @@ endif()
# GTest
add_subdirectory(gtests)
+
+# GBenchmark
+add_subdirectory(gbenchmark)
diff --git a/tests/gbenchmark/CMakeLists.txt b/tests/gbenchmark/CMakeLists.txt
new file mode 100644
index 00000000000..1670e9af7e6
--- /dev/null
+++ b/tests/gbenchmark/CMakeLists.txt
@@ -0,0 +1,20 @@
+if(WITH_BENCHMARK_TESTS)
+ set(INC
+ .
+ ../../extern/gbenchmark/include/
+ )
+
+ set(INC_SYS
+
+ )
+
+ set(SRC
+ gbenchmark_test.cc
+ )
+
+ set(LIB
+ extern_gbenchmark
+ )
+
+ blender_add_test_executable(benchmark "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
+endif()
diff --git a/tests/gbenchmark/gbenchmark_test.cc b/tests/gbenchmark/gbenchmark_test.cc
new file mode 100644
index 00000000000..9884d9611f7
--- /dev/null
+++ b/tests/gbenchmark/gbenchmark_test.cc
@@ -0,0 +1,18 @@
+#include <benchmark/benchmark.h>
+
+static void BM_StringCreation(benchmark::State &state)
+{
+ for (auto _ : state)
+ std::string empty_string;
+}
+// Register the function as a benchmark
+BENCHMARK(BM_StringCreation);
+
+// Define another benchmark
+static void BM_StringCopy(benchmark::State &state)
+{
+ std::string x = "hello";
+ for (auto _ : state)
+ std::string copy(x);
+}
+BENCHMARK(BM_StringCopy);
More information about the Bf-blender-cvs
mailing list