-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix clang-tidy false positive. - Added new "benchmark" suite. - The suite now has benchmark of the `cetl::function` (comparing with `std::function` and pure lambda): ``` 2024-12-03T12:04:03+02:00 Running /home/sergei/Develop/git/OpenCyphal/CETL/cetlvast/cmake-build-release/suites/benchmark/benchmark_pmr_function Run on (16 X 4791.28 MHz CPU s) CPU Caches: L1 Data 32 KiB (x8) L1 Instruction 32 KiB (x8) L2 Unified 1024 KiB (x8) L3 Unified 16384 KiB (x1) Load Average: 0.73, 1.78, 2.14 -------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------- BM_CetlFn_call/1000 1030 ns 1030 ns 672510 BM_StdFn_call/1000 1026 ns 1026 ns 690998 BM_Lambda_call/1000 206 ns 206 ns 3390901 Process finished with exit code 0 ```
- Loading branch information
Showing
4 changed files
with
112 additions
and
2 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
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,36 @@ | ||
# | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.22.0) | ||
|
||
project(cetlvast_benchmark CXX) | ||
|
||
find_package(benchmark REQUIRED) | ||
|
||
file(GLOB_RECURSE TEST_SOURCES | ||
LIST_DIRECTORIES false | ||
CONFIGURE_DEPENDS | ||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} | ||
benchmark_*.cpp **/benchmark_*.cpp | ||
) | ||
|
||
set(ALL_TESTS_BUILD "") | ||
|
||
foreach(TEST_SOURCE ${TEST_SOURCES}) | ||
|
||
cmake_path(GET TEST_SOURCE STEM TEST_NAME) | ||
|
||
add_executable(${TEST_NAME} ${TEST_SOURCE}) | ||
target_link_libraries(${TEST_NAME} cetl benchmark::benchmark) | ||
|
||
list(APPEND ALL_TESTS_BUILD ${TEST_NAME}) | ||
|
||
endforeach() | ||
|
||
add_custom_target( | ||
build_benchmarks | ||
DEPENDS | ||
${ALL_TESTS_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <cetl/pmr/function.hpp> | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
namespace | ||
{ | ||
|
||
void BM_CetlFn_call(benchmark::State& state) | ||
{ | ||
cetl::pmr::function<int64_t(int64_t), 16> fn = [](int64_t i) { | ||
benchmark::DoNotOptimize(i); | ||
return i; | ||
}; | ||
for (auto _ : state) | ||
{ | ||
int64_t res = 0; | ||
const auto lim = state.range(); | ||
for (int i = 0; i < lim; ++i) | ||
{ | ||
res += fn(i); | ||
} | ||
benchmark::DoNotOptimize(res); | ||
} | ||
} | ||
|
||
void BM_StdFn_call(benchmark::State& state) | ||
{ | ||
std::function<int64_t(int64_t)> fn = [](int64_t i) { | ||
benchmark::DoNotOptimize(i); | ||
return i; | ||
}; | ||
for (auto _ : state) | ||
{ | ||
int64_t res = 0; | ||
const auto lim = state.range(); | ||
for (int i = 0; i < lim; ++i) | ||
{ | ||
res += fn(i); | ||
} | ||
benchmark::DoNotOptimize(res); | ||
} | ||
} | ||
|
||
void BM_Lambda_call(benchmark::State& state) | ||
{ | ||
auto fn = [](int64_t i) { | ||
benchmark::DoNotOptimize(i); | ||
return i; | ||
}; | ||
for (auto _ : state) | ||
{ | ||
int64_t res = 0; | ||
const auto lim = state.range(); | ||
for (int i = 0; i < lim; ++i) | ||
{ | ||
res += fn(i); | ||
} | ||
benchmark::DoNotOptimize(res); | ||
} | ||
(void) fn; | ||
} | ||
|
||
} // namespace | ||
|
||
BENCHMARK(BM_CetlFn_call)->Arg(1000); | ||
BENCHMARK(BM_StdFn_call)->Arg(1000); | ||
BENCHMARK(BM_Lambda_call)->Arg(1000); | ||
|
||
BENCHMARK_MAIN(); |
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