commit 594bb23b98d8c94b7e4892abfb813e505185cd88 parent b20b12d27fcbd4be91f29697107e10a4e36fcda9 Author: David Freifeld <freifeld.david@gmail.com> Date: Thu, 30 Jul 2020 16:26:17 -0700 Experiments show cwise functions are faster Diffstat:
| A | tests/simd.cpp | | | 21 | +++++++++++++++++++++ |
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/tests/simd.cpp b/tests/simd.cpp @@ -0,0 +1,21 @@ +#include <Eigen/Dense> +#include <ctime> +#include <iostream> +#include <cmath> + +int main() +{ + Eigen::MatrixXf a = Eigen::MatrixXf::Random(1000, 1000); + + auto simd_start = std::chrono::high_resolution_clock::now(); + a.array().exp().matrix(); + auto simd_end = std::chrono::high_resolution_clock::now(); + auto start = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < a.rows(); i++) { + for (int j = 0; j < a.cols(); j++) { + a(i,j) = exp(a(i,j)); + } + } + auto end = std::chrono::high_resolution_clock::now(); + std::cout << "SIMD: " << std::chrono::duration_cast<std::chrono::nanoseconds>(simd_end - simd_start).count() << " NORMAL: " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() << "\n"; +}