gtsam
3rdparty
Eigen
bench
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>
19
void
copy_matrix
(
MatrixType
&
m
)
20
{
21
MatrixType
tmp(
m
);
22
m
= tmp;
23
}
24
25
template
<
typename
MatrixType>
26
void
move_matrix
(
MatrixType
&&
m
)
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
{
35
using
MatrixType
=
Eigen::Matrix<Eigen::MovableScalar<Scalar>
,1,10>;
36
Eigen::BenchTimer
t
;
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
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
move_matrix
void move_matrix(MatrixType &&m)
Definition:
bench_move_semantics.cpp:26
data
int data[]
Definition:
Map_placement_new.cpp:1
Eigen::BenchTimer
Definition:
BenchTimer.h:59
main
int main()
Definition:
bench_move_semantics.cpp:51
bench
void bench(const std::string &label)
Definition:
bench_move_semantics.cpp:33
BENCH
#define BENCH(TIMER, TRIES, REP, CODE)
Definition:
BenchTimer.h:174
m
Matrix3f m
Definition:
AngleAxis_mimic_euler.cpp:1
Eigen::CPU_TIMER
@ CPU_TIMER
Definition:
BenchTimer.h:48
BenchTimer.h
copy_matrix
void copy_matrix(MatrixType &m)
Definition:
bench_move_semantics.cpp:19
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition:
3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
align_3::t
Point2 t(10, 10)
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:54