1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-11-14 22:04:57 +00:00
gnss-sdr/src/tests/benchmarks/benchmark_preamble.cc

74 lines
2.2 KiB
C++
Raw Normal View History

2020-06-21 19:10:22 +00:00
/*!
* \file benchmark_preamble.cc
* \brief Benchmark for preamble conversion implementations
* \author Carles Fernandez-Prades, 2020. cfernandez(at)cttc.es
*
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
2020-06-21 19:10:22 +00:00
*
* Copyright (C) 2020 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
2020-06-21 19:10:22 +00:00
*/
#include "GPS_L1_CA.h"
#include <benchmark/benchmark.h>
#include <algorithm>
#include <array>
void bm_forloop(benchmark::State& state)
{
2020-07-28 09:02:29 +00:00
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
volatile int32_t res; // Prevent the compiler from optimizing the loop away
2020-06-21 19:10:22 +00:00
while (state.KeepRunning())
{
2020-06-24 11:59:50 +00:00
int32_t n = 0;
2020-07-28 09:02:29 +00:00
for (int32_t i = 0; i < GPS_CA_PREAMBLE_LENGTH_SYMBOLS; i++)
2020-06-21 19:10:22 +00:00
{
2020-07-28 09:02:29 +00:00
if (GPS_CA_PREAMBLE_SYMBOLS_STR[i] == '1')
2020-06-21 19:10:22 +00:00
{
d_preamble_samples[n] = 1;
n++;
}
else
{
d_preamble_samples[n] = -1;
n++;
}
}
2020-07-28 09:02:29 +00:00
res = d_preamble_samples[GPS_CA_PREAMBLE_LENGTH_SYMBOLS - 1];
}
if (res > 1)
{
// Avoid unused-but-set-variable warning
2020-06-21 19:10:22 +00:00
}
}
2020-06-24 11:59:50 +00:00
void bm_generate(benchmark::State& state)
2020-06-21 19:10:22 +00:00
{
2020-07-28 09:02:29 +00:00
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
volatile int32_t res; // Prevent the compiler from optimizing the loop away
2020-06-21 19:10:22 +00:00
while (state.KeepRunning())
{
2020-07-28 09:02:29 +00:00
std::generate(d_preamble_samples.begin(), d_preamble_samples.end(), [n = 0]() mutable { return (GPS_CA_PREAMBLE_SYMBOLS_STR[n++] == '1' ? 1 : -1); });
res = d_preamble_samples[GPS_CA_PREAMBLE_LENGTH_SYMBOLS - 1];
}
if (res > 1)
{
// Avoid unused-but-set-variable warning
2020-06-21 19:10:22 +00:00
}
}
BENCHMARK(bm_forloop);
2020-06-24 11:59:50 +00:00
BENCHMARK(bm_generate);
2020-06-21 19:10:22 +00:00
BENCHMARK_MAIN();