| 
									
										
										
										
											2010-01-20 04:59:22 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * @file timeMatrix.cpp | 
					
						
							|  |  |  |  * @brief Performs timing and profiling for Matrix operations | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2010-01-20 05:49:22 +08:00
										 |  |  | #include <boost/timer.hpp>
 | 
					
						
							| 
									
										
										
										
											2010-01-20 04:59:22 +08:00
										 |  |  | #include "Matrix.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-20 05:49:22 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Results: | 
					
						
							|  |  |  |  * Alex's Machine: | 
					
						
							|  |  |  |  *  - no pass: 0.1818 sec | 
					
						
							|  |  |  |  *  - pass   : 0.1802 sec | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | double timeCollect(size_t p, size_t m, size_t n, bool passDims, size_t reps) { | 
					
						
							| 
									
										
										
										
											2010-01-20 04:59:22 +08:00
										 |  |  | 	// create a large number of matrices
 | 
					
						
							| 
									
										
										
										
											2010-01-20 05:49:22 +08:00
										 |  |  | 	// p =  number of matrices
 | 
					
						
							|  |  |  | 	// m =  rows per matrix
 | 
					
						
							|  |  |  | 	// n =  columns per matrix
 | 
					
						
							|  |  |  | 	// reps = number of repetitions
 | 
					
						
							| 
									
										
										
										
											2010-01-20 04:59:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// fill the matrices with identities
 | 
					
						
							|  |  |  | 	vector<const Matrix *> matrices; | 
					
						
							|  |  |  | 	for (int i=0; i<p;++i) { | 
					
						
							|  |  |  | 		Matrix * M = new Matrix; | 
					
						
							|  |  |  | 		(*M) = eye(m,n); | 
					
						
							|  |  |  | 		matrices.push_back(M); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// start timing
 | 
					
						
							|  |  |  | 	Matrix result; | 
					
						
							| 
									
										
										
										
											2010-01-20 05:49:22 +08:00
										 |  |  | 	double elapsed; | 
					
						
							| 
									
										
										
										
											2010-01-20 04:59:22 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-01-20 05:49:22 +08:00
										 |  |  | 		boost::timer t; | 
					
						
							| 
									
										
										
										
											2010-01-20 04:59:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-20 05:49:22 +08:00
										 |  |  | 		if (passDims) | 
					
						
							|  |  |  | 			for (int i=0; i<reps; ++i) | 
					
						
							|  |  |  | 				result = collect(matrices, m, n); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			for (int i=0; i<reps; ++i) | 
					
						
							|  |  |  | 				result = collect(matrices); | 
					
						
							|  |  |  | 		elapsed = t.elapsed(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-20 04:59:22 +08:00
										 |  |  | 	// delete the matrices
 | 
					
						
							|  |  |  | 	for (int i=0; i<p;++i) { | 
					
						
							|  |  |  | 		delete matrices[i]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-20 05:49:22 +08:00
										 |  |  | 	return elapsed/reps; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char ** argv) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Time collect()
 | 
					
						
							|  |  |  | 	cout << "Starting Matrix::collect() Timing" << endl; | 
					
						
							|  |  |  | 	size_t p = 100000; size_t m = 10; size_t n = 12; size_t reps = 50; | 
					
						
							|  |  |  | 	double collect_time1 = timeCollect(p, m, n, false, reps); | 
					
						
							|  |  |  | 	double collect_time2 = timeCollect(p, m, n, true, reps); | 
					
						
							|  |  |  | 	cout << "Elapsed time for collect (no pass) [" << p << " (" << m << ", " << n << ") matrices] : " << collect_time1 << endl; | 
					
						
							|  |  |  | 	cout << "Elapsed time for collect (pass)    [" << p << " (" << m << ", " << n << ") matrices] : " << collect_time2 << endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-20 04:59:22 +08:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } |