aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/MovableScalar.h
diff options
context:
space:
mode:
authorGravatar Sebastien Boisvert <seb@boisvert.info>2020-06-11 23:43:25 +0000
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2020-06-11 23:43:25 +0000
commit39cbd6578fbf3a98d8a213c8ec3f5147557d065e (patch)
treecc04e0117d47268dbbf3a79cd851a7bcf7d5b1f0 /test/MovableScalar.h
parenta7d2552af8b34f6befba9988c36fe5d9723892e6 (diff)
Fix #1911: add benchmark for move semantics with fixed-size matrix
$ clang++ -O3 bench/bench_move_semantics.cpp -I. -std=c++11 \ -o bench_move_semantics $ ./bench_move_semantics float copy semantics: 1755.97 ms float move semantics: 55.063 ms double copy semantics: 2457.65 ms double move semantics: 55.034 ms
Diffstat (limited to 'test/MovableScalar.h')
-rw-r--r--test/MovableScalar.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/MovableScalar.h b/test/MovableScalar.h
new file mode 100644
index 000000000..6a90d037a
--- /dev/null
+++ b/test/MovableScalar.h
@@ -0,0 +1,35 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2020 Sebastien Boisvert <seb@boisvert.info>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MISC_MOVABLE_SCALAR_H
+#define EIGEN_MISC_MOVABLE_SCALAR_H
+
+#include <vector>
+
+namespace Eigen
+{
+template <typename Scalar, typename Base = std::vector<Scalar>>
+struct MovableScalar : public Base
+{
+ MovableScalar() = default;
+ ~MovableScalar() = default;
+ MovableScalar(const MovableScalar&) = default;
+ MovableScalar(MovableScalar&& other) = default;
+ MovableScalar& operator=(const MovableScalar&) = default;
+ MovableScalar& operator=(MovableScalar&& other) = default;
+ MovableScalar(Scalar scalar) : Base(100, scalar) {}
+
+ operator Scalar() const { return this->size() > 0 ? this->back() : Scalar(); }
+};
+
+template<> struct NumTraits<MovableScalar<float>> : GenericNumTraits<float> {};
+}
+
+#endif
+