2022-02-10 12:37:52 +00:00
|
|
|
/*!
|
|
|
|
* \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 <benchmark/benchmark.h>
|
|
|
|
#include <gnuradio/math.h>
|
|
|
|
#include <cmath>
|
|
|
|
#include <random>
|
|
|
|
|
2022-02-10 18:44:29 +00:00
|
|
|
void bm_std_atan2(benchmark::State& state)
|
2022-02-10 12:37:52 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2022-02-10 18:44:29 +00:00
|
|
|
if (c > 1.0)
|
|
|
|
{
|
|
|
|
// Avoid unused-but-set-variable warning
|
|
|
|
}
|
2022-02-10 12:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-10 18:44:29 +00:00
|
|
|
void bm_gr_fast_atan2f(benchmark::State& state)
|
2022-02-10 12:37:52 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2022-02-10 18:44:29 +00:00
|
|
|
if (c > 1.0)
|
|
|
|
{
|
|
|
|
// Avoid unused-but-set-variable warning
|
|
|
|
}
|
2022-02-10 12:37:52 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 18:44:29 +00:00
|
|
|
BENCHMARK(bm_std_atan2);
|
|
|
|
BENCHMARK(bm_gr_fast_atan2f);
|
2022-02-10 12:37:52 +00:00
|
|
|
|
|
|
|
BENCHMARK_MAIN();
|