bench_move_semantics.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2020 Sebastien Boisvert <seb@boisvert.info>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "BenchTimer.h"
11 #include "../test/MovableScalar.h"
12 
13 #include <Eigen/Core>
14 
15 #include <iostream>
16 #include <utility>
17 
18 template <typename MatrixType>
20 {
21  MatrixType tmp(m);
22  m = tmp;
23 }
24 
25 template <typename MatrixType>
27 {
28  MatrixType tmp(std::move(m));
29  m = std::move(tmp);
30 }
31 
32 template<typename Scalar>
33 void bench(const std::string& label)
34 {
37 
38  int tries = 10;
39  int rep = 1000000;
40 
41  MatrixType data = MatrixType::Random().eval();
42  MatrixType dest;
43 
44  BENCH(t, tries, rep, copy_matrix(data));
45  std::cout << label << " copy semantics: " << 1e3*t.best(Eigen::CPU_TIMER) << " ms" << std::endl;
46 
47  BENCH(t, tries, rep, move_matrix(std::move(data)));
48  std::cout << label << " move semantics: " << 1e3*t.best(Eigen::CPU_TIMER) << " ms" << std::endl;
49 }
50 
51 int main()
52 {
53  bench<float>("float");
54  bench<double>("double");
55  return 0;
56 }
57 
Matrix3f m
void move_matrix(MatrixType &&m)
MatrixXf MatrixType
double best(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:111
void bench(const std::string &label)
int data[]
int main()
void copy_matrix(MatrixType &m)
#define BENCH(TIMER, TRIES, REP, CODE)
Definition: BenchTimer.h:174
The matrix class, also used for vectors and row-vectors.
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:33:57