bench_move_semantics.cpp File Reference
#include "BenchTimer.h"
#include "../test/MovableScalar.h"
#include <Eigen/Core>
#include <iostream>
#include <utility>

Functions

template<typename MatrixType >
void copy_matrix (MatrixType &m)
 
template<typename MatrixType >
void move_matrix (MatrixType &&m)
 
template<typename Scalar >
void bench (const std::string &label)
 
int main ()
 

Function Documentation

◆ bench()

template<typename Scalar >
void bench ( const std::string &  label)
31  {
34 
35  int tries = 10;
36  int rep = 1000000;
37 
38  MatrixType data = MatrixType::Random().eval();
39  MatrixType dest;
40 
41  BENCH(t, tries, rep, copy_matrix(data));
42  std::cout << label << " copy semantics: " << 1e3 * t.best(Eigen::CPU_TIMER) << " ms" << std::endl;
43 
44  BENCH(t, tries, rep, move_matrix(std::move(data)));
45  std::cout << label << " move semantics: " << 1e3 * t.best(Eigen::CPU_TIMER) << " ms" << std::endl;
46 }
#define BENCH(TIMER, TRIES, REP, CODE)
Definition: BenchTimer.h:150
int data[]
Definition: Map_placement_new.cpp:1
void move_matrix(MatrixType &&m)
Definition: bench_move_semantics.cpp:25
void copy_matrix(MatrixType &m)
Definition: bench_move_semantics.cpp:19
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Definition: BenchTimer.h:55
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
@ CPU_TIMER
Definition: BenchTimer.h:46
label
Definition: UniformPSDSelfTest.py:24
t
Definition: plotPSD.py:36

References BENCH, copy_matrix(), Eigen::CPU_TIMER, data, UniformPSDSelfTest::label, move_matrix(), and plotPSD::t.

◆ copy_matrix()

template<typename MatrixType >
void copy_matrix ( MatrixType m)
19  {
20  MatrixType tmp(m);
21  m = tmp;
22 }
int * m
Definition: level2_cplx_impl.h:294
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365

References m, and tmp.

Referenced by bench().

◆ main()

int main ( )
48  {
49  bench<float>("float");
50  bench<double>("double");
51  return 0;
52 }

◆ move_matrix()

template<typename MatrixType >
void move_matrix ( MatrixType &&  m)
25  {
26  MatrixType tmp(std::move(m));
27  m = std::move(tmp);
28 }

References m, and tmp.

Referenced by bench().