1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-11-15 06:14:58 +00:00
gnss-sdr/tests/benchmarks/benchmark_copy.cc

81 lines
1.9 KiB
C++
Raw Normal View History

2020-06-21 19:10:22 +00:00
/*!
* \file benchmark_copy.cc
* \brief Benchmark for memory copy implementations
* \author Carles Fernandez-Prades, 2020. cfernandez(at)cttc.es
*
* Based on https://stackoverflow.com/a/40109182
*
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
2020-06-21 19:10:22 +00:00
*
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
2020-06-21 19:10:22 +00:00
* This file is part of GNSS-SDR.
*
* Copyright (C) 2020 (see AUTHORS file for a list of contributors)
2020-06-21 19:10:22 +00:00
* 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 <benchmark/benchmark.h>
#include <algorithm>
#include <complex>
#include <cstring>
#include <vector>
constexpr int N = 8184;
void bm_memcpy(benchmark::State& state)
{
std::vector<std::complex<float>> orig(N);
std::vector<std::complex<float>> dest(N);
while (state.KeepRunning())
{
memcpy(dest.data(), orig.data(), N * sizeof(std::complex<float>));
}
}
void bm_stdmemcpy(benchmark::State& state)
{
std::vector<std::complex<float>> orig(N);
std::vector<std::complex<float>> dest(N);
while (state.KeepRunning())
{
std::memcpy(dest.data(), orig.data(), N * sizeof(std::complex<float>));
}
}
void bm_stdcopy(benchmark::State& state)
{
std::vector<std::complex<float>> orig(N);
std::vector<std::complex<float>> dest(N);
while (state.KeepRunning())
{
std::copy(orig.begin(), orig.end(), dest.begin());
}
}
void bm_stdcopy_n(benchmark::State& state)
{
std::vector<std::complex<float>> orig(N);
std::vector<std::complex<float>> dest(N);
while (state.KeepRunning())
{
std::copy_n(orig.begin(), N, dest.begin());
}
}
BENCHMARK(bm_memcpy);
BENCHMARK(bm_stdmemcpy);
BENCHMARK(bm_stdcopy);
BENCHMARK(bm_stdcopy_n);
BENCHMARK_MAIN();