aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/basicbenchmark.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-03-09 16:13:47 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-03-09 16:13:47 +0000
commit9d9d81ad71a52c33ba4db9f8a6059d435d279316 (patch)
treed12a85ca594af99b04ce32f652ae67bf0baf228b /bench/basicbenchmark.h
parentf64311e07de95694187e5d6d5d2e3cd118302076 (diff)
* basic support for multicore CPU via a .evalOMP() which
internaly uses OpenMP if enabled at compile time. * added a bench/ folder with a couple benchmarks and benchmark tools.
Diffstat (limited to 'bench/basicbenchmark.h')
-rw-r--r--bench/basicbenchmark.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/bench/basicbenchmark.h b/bench/basicbenchmark.h
new file mode 100644
index 000000000..60e1c0258
--- /dev/null
+++ b/bench/basicbenchmark.h
@@ -0,0 +1,59 @@
+
+enum {LazyEval, EarlyEval, OmpEval};
+
+template<int Mode, typename MatrixType>
+void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations) __attribute__((noinline));
+
+template<int Mode, typename MatrixType>
+void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations)
+{
+ for(int a = 0; a < iterations; a++)
+ {
+ if (Mode==LazyEval)
+ {
+ asm("#begin_bench_loop LazyEval");
+ if (MatrixType::Traits::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
+ m = (I + 0.00005 * (m + m.lazyProduct(m))).eval();
+ }
+ else if (Mode==OmpEval)
+ {
+ asm("#begin_bench_loop OmpEval");
+ if (MatrixType::Traits::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
+ m = (I + 0.00005 * (m + m.lazyProduct(m))).evalOMP();
+ }
+ else
+ {
+ asm("#begin_bench_loop EarlyEval");
+ if (MatrixType::Traits::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
+ m = I + 0.00005 * (m + m * m);
+ }
+ asm("#end_bench_loop");
+ }
+}
+
+template<int Mode, typename MatrixType>
+double benchBasic(const MatrixType& mat, int size, int tries) __attribute__((noinline));
+
+template<int Mode, typename MatrixType>
+double benchBasic(const MatrixType& mat, int iterations, int tries)
+{
+ const int rows = mat.rows();
+ const int cols = mat.cols();
+
+ MatrixType I(rows,cols);
+ MatrixType m(rows,cols);
+
+ initMatrix_identity(I);
+
+ Eigen::BenchTimer timer;
+ for(uint t=0; t<tries; ++t)
+ {
+ initMatrix_random(m);
+ timer.start();
+ benchBasic_loop<Mode>(I, m, iterations);
+ timer.stop();
+ cerr << m;
+ }
+ return timer.value();
+};
+