| 
									
										
										
										
											2008-03-10 00:13:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-30 00:10:08 +08:00
										 |  |  | #ifndef EIGEN_BENCH_BASICBENCH_H
 | 
					
						
							|  |  |  | #define EIGEN_BENCH_BASICBENCH_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-10 00:13:47 +08:00
										 |  |  | 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"); | 
					
						
							| 
									
										
										
										
											2008-03-13 01:17:36 +08:00
										 |  |  |       if (MatrixType::SizeAtCompileTime != Eigen::Dynamic) asm("#fixedsize"); | 
					
						
							| 
									
										
										
										
											2021-04-19 21:46:38 +08:00
										 |  |  |       m = (I + 0.00005 * (m + m.lazyProduct(m))).eval(); | 
					
						
							| 
									
										
										
										
											2008-03-10 00:13:47 +08:00
										 |  |  |     } else if (Mode == OmpEval) { | 
					
						
							|  |  |  |       asm("#begin_bench_loop OmpEval"); | 
					
						
							| 
									
										
										
										
											2008-03-13 01:17:36 +08:00
										 |  |  |       if (MatrixType::SizeAtCompileTime != Eigen::Dynamic) asm("#fixedsize"); | 
					
						
							| 
									
										
										
										
											2021-04-19 21:46:38 +08:00
										 |  |  |       m = (I + 0.00005 * (m + m.lazyProduct(m))).eval(); | 
					
						
							| 
									
										
										
										
											2008-03-10 00:13:47 +08:00
										 |  |  |     } else { | 
					
						
							|  |  |  |       asm("#begin_bench_loop EarlyEval"); | 
					
						
							| 
									
										
										
										
											2008-03-13 01:17:36 +08:00
										 |  |  |       if (MatrixType::SizeAtCompileTime != Eigen::Dynamic) asm("#fixedsize"); | 
					
						
							| 
									
										
										
										
											2008-03-10 00:13:47 +08:00
										 |  |  |       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(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-30 00:10:08 +08:00
										 |  |  | #endif  // EIGEN_BENCH_BASICBENCH_H
 |