From 9ccaec5e39391cef9b8a204be581600bca004f6b Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Fri, 2 Feb 2024 07:38:58 +0100 Subject: [PATCH 1/4] Make benchmark sample and update docs --- .../app_benchmark_trapezoid_integral.cpp | 17 +++++++--- ref_app/src/app/benchmark/readme.md | 31 ++++++++++++++++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp b/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp index f49d8dd2d..18ea9cccc 100644 --- a/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp +++ b/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2022. +// Copyright Christopher Kormanyos 2021 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -9,11 +9,18 @@ #if(APP_BENCHMARK_TYPE == APP_BENCHMARK_TYPE_TRAPEZOID_INTEGRAL) +// See also: https://godbolt.org/z/j4aM9vzr9 + #include +#if (defined(__has_include) && (__has_include())) +#include +#else #include +#endif #include +#include #include #include @@ -49,7 +56,7 @@ namespace auto app::benchmark::run_trapezoid_integral() -> bool { - using my_float_type = std::floatmax_t; + using my_float_type = std::float64_t; static_assert((std::numeric_limits::digits >= 24), "Error: Incorrect my_float_type type definition"); @@ -58,7 +65,7 @@ auto app::benchmark::run_trapezoid_integral() -> bool static_cast ( std::numeric_limits::epsilon() - * static_cast(FLOATMAX_C(100.0)) + * static_cast(100.0L) ); // Compute y = cyl_bessel_j(2, 1.23) = 0.16636938378681407351267852431513159437103348245333 @@ -67,13 +74,13 @@ auto app::benchmark::run_trapezoid_integral() -> bool cyl_bessel_j ( UINT8_C(2), - static_cast(FLOATMAX_C(1.23)) + static_cast(1.23L) ); const bool app_benchmark_result_is_ok = detail::is_close_fraction ( - static_cast(FLOATMAX_C(0.1663693837868140735126785243)), + static_cast(0.1663693837868140735126785243L), j2, app_benchmark_tolerance ); diff --git a/ref_app/src/app/benchmark/readme.md b/ref_app/src/app/benchmark/readme.md index 38ba47f29..663d57bbd 100644 --- a/ref_app/src/app/benchmark/readme.md +++ b/ref_app/src/app/benchmark/readme.md @@ -1,4 +1,17 @@ -# Benchmarks and Performance Classes +Real-Time-C++ - Benchmarks +================== + +# Benchmarks and Performance Classes + +

+ + Build Status + + Boost Software License 1.0 + + +

+ ## Benchmarks @@ -9,6 +22,22 @@ - A benchmark digital I/O pin is toggled hi/lo at begin/end of the benchmark run providing for oscilloscope real-time measurement. - The benchmarks provide scalable, portable means for identifying the performance class of the microcontroller. +## Executing the benchmarks + +Executing the benchmarks is straightforward. Select the desired benchmark and +activate its corresponding flag in [app_benchmark.h](https://github.com/ckormanyos/real-time-cpp/blob/master/ref_app/src/app/benchmark/app_benchmark_none.h) +Compile the reference application and run on the target. +The benchmark timing will be reflected on microcontroller-mcal's corresponding +benchmark port pin. + +Individual benchmarks can also be run standalone on any C++ cplatform. +In the following [short link](https://godbolt.org/z/j4aM9vzr9) +to [godbolt](https://godbolt.org), we have adapted the +`APP_BENCHMARK_TYPE_TRAPEZOID_INTEGRAL` benchmark for standalone use. +Note also that the presence of the `main()` subroutine is activated with +the compiler definition `APP_BENCHMARK_STANDALONE_MAIN`. + + ## Benchmark details - ![app_benchmark_none.cpp](https://github.com/ckormanyos/real-time-cpp/blob/master/ref_app/src/app/benchmark/app_benchmark_none.cpp) via `#define APP_BENCHMARK_TYPE_NONE` is an empty benchmark with merely a Boolean function call returning `true`. From c140e355ba44335992827c9c0a61d73bfc66efe4 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Fri, 2 Feb 2024 07:42:36 +0100 Subject: [PATCH 2/4] Update benchmark docs --- ref_app/src/app/benchmark/readme.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ref_app/src/app/benchmark/readme.md b/ref_app/src/app/benchmark/readme.md index 663d57bbd..829d7af27 100644 --- a/ref_app/src/app/benchmark/readme.md +++ b/ref_app/src/app/benchmark/readme.md @@ -1,8 +1,6 @@ Real-Time-C++ - Benchmarks ================== -# Benchmarks and Performance Classes -

Build Status @@ -13,7 +11,7 @@

-## Benchmarks +## Implementation details - The benchmarks provide code that exercises microcontroller performance. - Various efficiency aspects are emphasized such as integral and floating-point calculations, looping, branching, etc. @@ -38,7 +36,7 @@ Note also that the presence of the `main()` subroutine is activated with the compiler definition `APP_BENCHMARK_STANDALONE_MAIN`. -## Benchmark details +## Individual benchmarks - ![app_benchmark_none.cpp](https://github.com/ckormanyos/real-time-cpp/blob/master/ref_app/src/app/benchmark/app_benchmark_none.cpp) via `#define APP_BENCHMARK_TYPE_NONE` is an empty benchmark with merely a Boolean function call returning `true`. - ![app_benchmark_complex.cpp](https://github.com/ckormanyos/real-time-cpp/blob/master/ref_app/src/app/benchmark/app_benchmark_complex.cpp) via `#define APP_BENCHMARK_TYPE_COMPLEX` computes a floating-point complex-valued trigonometric sine function using the [`extended_complex::complex`](https://github.com/ckormanyos/real-time-cpp/blob/master/ref_app/src/math/extended_complex/extended_complex.h) template class. @@ -63,7 +61,7 @@ the compiler definition `APP_BENCHMARK_STANDALONE_MAIN`. - ![app_benchmark_ecc_generic_ecc.cpp](https://github.com/ckormanyos/real-time-cpp/blob/master/ref_app/src/app/benchmark/app_benchmark_ecc_generic_ecc.cpp) via `#define APP_BENCHMARK_TYPE_ECC_GENERIC_ECC` provides an intuitive view on elliptic-curve algebra, depicting a well-known $256$-bit cryptographic key-gen/sign/verify method. This benchmark is actually too lengthy to run on most of our embedded targets (other than BBB or RPI-zero) and adaptions of OS/watchdog are required in order to run this benchmark on the metal. - ![app_benchmark_non_std_decimal.cpp](https://github.com/ckormanyos/real-time-cpp/blob/master/ref_app/src/app/benchmark/app_benchmark_non_std_decimal.cpp) via `#define APP_BENCHMARK_TYPE_NON_STD_DECIMAL` carries out a $64$-bit decimal-floating-point calculation of the exponential function using the contemporary [cpplliance/decimal](https://github.com/cppalliance/decimal) library. This benchmark does not, at the moment, run on the AVR target, but requires a larger microcontroller such as one of the $32$-bit ARM(R) devices. -## Performance classes +## Benchmarks and performance classes Most of the benchmarks run on each supported target system. Experience with runs on the individual target systems reveal From 586fe43c323735174ea1caffda7502201f82fd60 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Fri, 2 Feb 2024 09:13:21 +0100 Subject: [PATCH 3/4] Update app_benchmark_trapezoid_integral.cpp --- .../benchmark/app_benchmark_trapezoid_integral.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp b/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp index 18ea9cccc..2889ce0d1 100644 --- a/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp +++ b/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // Copyright Christopher Kormanyos 2021 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt @@ -15,10 +15,15 @@ #if (defined(__has_include) && (__has_include())) #include -#else #include #endif +#if (defined(__STDCPP_FLOAT64_T__) && (__STDCPP_FLOAT64_T__ == 1)) +using my_float_type = std::float64_t; +#else +using my_float_type = float; +#endif + #include #include #include @@ -56,8 +61,6 @@ namespace auto app::benchmark::run_trapezoid_integral() -> bool { - using my_float_type = std::float64_t; - static_assert((std::numeric_limits::digits >= 24), "Error: Incorrect my_float_type type definition"); From f908a20340c0de69d4eaf108fa26fefd60b967e4 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Fri, 2 Feb 2024 09:26:18 +0100 Subject: [PATCH 4/4] Update app_benchmark_trapezoid_integral.cpp --- .../benchmark/app_benchmark_trapezoid_integral.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp b/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp index 2889ce0d1..6a9b71f41 100644 --- a/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp +++ b/ref_app/src/app/benchmark/app_benchmark_trapezoid_integral.cpp @@ -14,14 +14,15 @@ #include #if (defined(__has_include) && (__has_include())) -#include -#include + #include + #if (defined(__STDCPP_FLOAT64_T__) && (__STDCPP_FLOAT64_T__ == 1)) + using my_float_type = std::float64_t; + #else + using my_float_type = float; #endif - -#if (defined(__STDCPP_FLOAT64_T__) && (__STDCPP_FLOAT64_T__ == 1)) -using my_float_type = std::float64_t; #else -using my_float_type = float; + #include + using my_float_type = std::floatmax_t; #endif #include