1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-07-02 09:53:15 +00:00
gnss-sdr/src/tests/benchmarks/benchmark_preamble.cc

62 lines
1.7 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
*
*
* -------------------------------------------------------------------------
*
* 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
*
* -------------------------------------------------------------------------
*/
#include "GPS_L1_CA.h"
#include <benchmark/benchmark.h>
#include <algorithm>
#include <array>
void bm_forloop(benchmark::State& state)
{
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_BITS> d_preamble_samples{};
while (state.KeepRunning())
{
2020-06-24 11:59:50 +00:00
int32_t n = 0;
2020-06-21 19:10:22 +00:00
for (int32_t i = 0; i < GPS_CA_PREAMBLE_LENGTH_BITS; i++)
{
if (GPS_CA_PREAMBLE[i] == '1')
{
d_preamble_samples[n] = 1;
n++;
}
else
{
d_preamble_samples[n] = -1;
n++;
}
}
}
}
2020-06-24 11:59:50 +00:00
void bm_generate(benchmark::State& state)
2020-06-21 19:10:22 +00:00
{
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_BITS> d_preamble_samples{};
while (state.KeepRunning())
{
std::generate(d_preamble_samples.begin(), d_preamble_samples.end(), [n = 0]() mutable { return (GPS_CA_PREAMBLE[n++] == '1' ? 1 : -1); });
}
}
BENCHMARK(bm_forloop);
2020-06-24 11:59:50 +00:00
BENCHMARK(bm_generate);
2020-06-21 19:10:22 +00:00
BENCHMARK_MAIN();