1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-18 21:23:02 +00:00

Benchmark with a longer string

This commit is contained in:
Carles Fernandez 2020-07-28 11:02:29 +02:00
parent b33d7ba739
commit 6cc96b039f
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D

View File

@ -25,13 +25,14 @@
void bm_forloop(benchmark::State& state)
{
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_BITS> d_preamble_samples{};
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
volatile int32_t res; // Prevent the compiler from optimizing the loop away
while (state.KeepRunning())
{
int32_t n = 0;
for (int32_t i = 0; i < GPS_CA_PREAMBLE_LENGTH_BITS; i++)
for (int32_t i = 0; i < GPS_CA_PREAMBLE_LENGTH_SYMBOLS; i++)
{
if (GPS_CA_PREAMBLE[i] == '1')
if (GPS_CA_PREAMBLE_SYMBOLS_STR[i] == '1')
{
d_preamble_samples[n] = 1;
n++;
@ -42,16 +43,27 @@ void bm_forloop(benchmark::State& state)
n++;
}
}
res = d_preamble_samples[GPS_CA_PREAMBLE_LENGTH_SYMBOLS - 1];
}
if (res > 1)
{
// Avoid unused-but-set-variable warning
}
}
void bm_generate(benchmark::State& state)
{
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_BITS> d_preamble_samples{};
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
volatile int32_t res; // Prevent the compiler from optimizing the loop away
while (state.KeepRunning())
{
std::generate(d_preamble_samples.begin(), d_preamble_samples.end(), [n = 0]() mutable { return (GPS_CA_PREAMBLE[n++] == '1' ? 1 : -1); });
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
}
}