diff --git a/src/tests/benchmarks/CMakeLists.txt b/src/tests/benchmarks/CMakeLists.txt index c5fddced7..680a616f5 100644 --- a/src/tests/benchmarks/CMakeLists.txt +++ b/src/tests/benchmarks/CMakeLists.txt @@ -102,6 +102,7 @@ add_benchmark(benchmark_copy) add_benchmark(benchmark_preamble core_system_parameters) add_benchmark(benchmark_detector core_system_parameters) add_benchmark(benchmark_reed_solomon core_system_parameters) +add_benchmark(benchmark_atan2 Gnuradio::runtime) if(has_std_plus_void) target_compile_definitions(benchmark_detector PRIVATE -DCOMPILER_HAS_STD_PLUS_VOID=1) diff --git a/src/tests/benchmarks/benchmark_atan2.cc b/src/tests/benchmarks/benchmark_atan2.cc new file mode 100644 index 000000000..543813785 --- /dev/null +++ b/src/tests/benchmarks/benchmark_atan2.cc @@ -0,0 +1,57 @@ +/*! + * \file benchmark_atan2.cc + * \brief Benchmark for atan2 implementations + * \author Carles Fernandez-Prades, 2022. cfernandez(at)cttc.es + * + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2022 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include +#include +#include +#include + +void bm_atan2(benchmark::State& state) +{ + std::random_device rd; + std::default_random_engine e2(rd()); + std::uniform_real_distribution<> dist(-1.0, 1.0); + + float a = dist(e2); + float b = dist(e2); + float c; + while (state.KeepRunning()) + { + c = std::atan2(a, b); + } +} + + +void bm_fast_atan2(benchmark::State& state) +{ + std::random_device rd; + std::default_random_engine e2(rd()); + std::uniform_real_distribution<> dist(-1.0, 1.0); + + float a = dist(e2); + float b = dist(e2); + float c; + while (state.KeepRunning()) + { + c = gr::fast_atan2f(a, b); + } +} + +BENCHMARK(bm_atan2); +BENCHMARK(bm_fast_atan2); + +BENCHMARK_MAIN();