From c8087b5318c7e383d08ca71a3a75387109422b56 Mon Sep 17 00:00:00 2001 From: Prateek Machiraju Date: Fri, 28 Jun 2019 13:51:33 -0400 Subject: [PATCH] Add vector benchmarks --- src/bench/bench_vector_creation.cpp | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bench/bench_vector_creation.cpp diff --git a/src/bench/bench_vector_creation.cpp b/src/bench/bench_vector_creation.cpp new file mode 100644 index 0000000..cc9a42d --- /dev/null +++ b/src/bench/bench_vector_creation.cpp @@ -0,0 +1,37 @@ +#include +#include +#include "FalconLibrary.h" + +static constexpr int kVectorSize = 500; + +template +struct ConstrainedPose { + S state; + double distance = 0.0; + double max_velocity = 0.0; + double min_acceleration = 0.0; + double max_acceleration = 0.0; +}; + +static void BM_VectorReserveAndPushBack(benchmark::State& state) { + for (auto _ : state) { + std::vector> vector; + vector.reserve(kVectorSize); + + for (int i = 0; i < kVectorSize; i++) { + vector.push_back({fl::Pose2dWithCurvature{}, 1.0 * i, 1.0 * i, 1.0 * i}); + } + } +} + +static void BM_VectorConstructor(benchmark::State& state) { + for (auto _ : state) { + std::vector> vector{kVectorSize}; + for (int i = 0; i < kVectorSize; i++) { + vector[i] = {fl::Pose2dWithCurvature{}, 1.0 * i, 1.0 * i, 1.0 * i}; + } + } +} + +BENCHMARK(BM_VectorReserveAndPushBack)->Arg(100)->Complexity()->Unit(benchmark::kMillisecond); +BENCHMARK(BM_VectorConstructor)->Arg(100)->Complexity()->Unit(benchmark::kMillisecond); \ No newline at end of file