mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Migrate Eigen benchmarks to the Google benchmark framework
libeigen/eigen!2132 Closes #3025 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
41
benchmarks/bench_move_semantics.cpp
Normal file
41
benchmarks/bench_move_semantics.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <Eigen/Core>
|
||||
#include "../test/MovableScalar.h"
|
||||
#include <utility>
|
||||
|
||||
template <typename MatrixType>
|
||||
void copy_matrix(MatrixType& m) {
|
||||
MatrixType tmp(m);
|
||||
m = tmp;
|
||||
}
|
||||
|
||||
template <typename MatrixType>
|
||||
void move_matrix(MatrixType&& m) {
|
||||
MatrixType tmp(std::move(m));
|
||||
m = std::move(tmp);
|
||||
}
|
||||
|
||||
template <typename Scalar>
|
||||
static void BM_CopySemantics(benchmark::State& state) {
|
||||
using MatrixType = Eigen::Matrix<Eigen::MovableScalar<Scalar>, 1, 10>;
|
||||
MatrixType data = MatrixType::Random().eval();
|
||||
for (auto _ : state) {
|
||||
copy_matrix(data);
|
||||
benchmark::DoNotOptimize(data.data());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Scalar>
|
||||
static void BM_MoveSemantics(benchmark::State& state) {
|
||||
using MatrixType = Eigen::Matrix<Eigen::MovableScalar<Scalar>, 1, 10>;
|
||||
MatrixType data = MatrixType::Random().eval();
|
||||
for (auto _ : state) {
|
||||
move_matrix(std::move(data));
|
||||
benchmark::DoNotOptimize(data.data());
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(BM_CopySemantics<float>);
|
||||
BENCHMARK(BM_MoveSemantics<float>);
|
||||
BENCHMARK(BM_CopySemantics<double>);
|
||||
BENCHMARK(BM_MoveSemantics<double>);
|
||||
Reference in New Issue
Block a user