forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add google benchmark library with example
Signed-off-by: Bogdan Vaneev <[email protected]>
- Loading branch information
Showing
7 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,5 @@ include/generated/* | |
.scannerwork/ | ||
iroha.conf | ||
peers.list | ||
cmake-build* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
add_library(benchmark UNKNOWN IMPORTED) | ||
|
||
find_path(benchmark_INCLUDE_DIR benchmark/benchmark.h) | ||
mark_as_advanced(benchmark_INCLUDE_DIR) | ||
|
||
find_library(benchmark_LIBRARY benchmark) | ||
mark_as_advanced(benchmark_LIBRARY) | ||
|
||
find_package(PackageHandleStandardArgs REQUIRED) | ||
find_package_handle_standard_args(benchmark DEFAULT_MSG | ||
benchmark_INCLUDE_DIR | ||
benchmark_LIBRARY | ||
) | ||
|
||
if (NOT benchmark_FOUND) | ||
externalproject_add(google_benchmark | ||
GIT_REPOSITORY https://github.com/google/benchmark | ||
GIT_TAG 'v1.2.0' | ||
INSTALL_COMMAND "" # remove install step | ||
TEST_COMMAND "" # remove test step | ||
UPDATE_COMMAND "" # remove update step | ||
) | ||
externalproject_get_property(google_benchmark binary_dir) | ||
set(benchmark_INCLUDE_DIR ${binary_dir}/include) | ||
set(benchmark_LIBRARY ${binary_dir}/lib/libbenchmark.a) | ||
file(MAKE_DIRECTORY ${benchmark_INCLUDE_DIR}) | ||
|
||
add_dependencies(benchmark google_benchmark) | ||
endif () | ||
|
||
set_target_properties(benchmark PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES ${benchmark_INCLUDE_DIR} | ||
IMPORTED_LOCATION ${benchmark_LIBRARY} | ||
INTERFACE_LINK_LIBRARIES "pthread" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# directory contains benchmarks | ||
add_executable(benchmark_example | ||
benchmark_example.cpp | ||
) | ||
target_link_libraries(benchmark_example | ||
benchmark | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. | ||
* http://soramitsu.co.jp | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/// | ||
/// Documentation is at https://github.com/google/benchmark | ||
/// | ||
/// General recommendations: | ||
/// - build with -DCMAKE_BUILD_TYPE=Release | ||
/// - disable CPU scaling (frequency changes depending on workload) | ||
/// - put initialization code in fixtures | ||
/// - write meaningful names for benchmarks | ||
/// | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <string> | ||
|
||
/// Test how long is empty std::string creation | ||
// define a static function, which accepts 'state' | ||
// function's name = benchmark's name | ||
static void BM_StringCreation(benchmark::State &state) { | ||
// define main benchmark loop | ||
while (state.KeepRunning()) { | ||
// define the code to be tested | ||
std::string empty_string; | ||
} | ||
} | ||
// define benchmark | ||
BENCHMARK(BM_StringCreation); | ||
|
||
/// That's all. More in documentation. | ||
|
||
// don't forget to include this: | ||
BENCHMARK_MAIN(); |