diff --git a/src/examples/test_matrix_prod.cpp b/src/examples/test_matrix_prod.cpp index 777483084a6d0b7c5dd6d47b9b0883a38fc37781..bd6ffddb6585f80c37b0d3a2e028492311ee2937 100644 --- a/src/examples/test_matrix_prod.cpp +++ b/src/examples/test_matrix_prod.cpp @@ -12,46 +12,50 @@ #include <iostream> #include <iomanip> -#define INIT_ALL\ +#define DECLARE_MATRICES(s) \ + Matrix<double, s, s, RowMajor> R1, R2, Ro; \ + Matrix<double, s, s, ColMajor> C1, C2, Co; + +#define INIT_MATRICES(s) \ R1.setRandom(s, s);\ R2.setRandom(s, s);\ C1.setRandom(s, s);\ - C2.setRandom(s, s); + C2.setRandom(s, s);\ + Ro.setRandom(s, s);\ + Co.setRandom(s, s); -#define LOOP(N,Mo,M1,M2) \ +#define LOOP_MATRIX(N,Mo,M1,M2) \ for (int i = 0; i < N; i++) \ { \ Mo = M1 * M2; \ - M1(2,2) += 0.000001; \ - M2(0,0) *= 1.000001; \ - /*M2 = Mo; */\ + M1(2,2) = Mo(2,2); \ } -#define EVALUATE(N,Mo,M1,M2) \ +#define EVALUATE_MATRIX(N,Mo,M1,M2) \ t0 = clock(); \ - LOOP(N,Mo,M1,M2) \ + LOOP_MATRIX(N,Mo,M1,M2) \ t1 = clock(); \ std::cout << std::setw(15) << Mo(2,2) << "\t"; #define EVALUATE_ALL \ - EVALUATE(N, Ro, R1, R2)\ + EVALUATE_MATRIX(N, Ro, R1, R2)\ std::cout << "Time Ro = R * R: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\ - EVALUATE(N, Ro, R1, C2)\ + EVALUATE_MATRIX(N, Ro, R1, C2)\ std::cout << "Time Ro = R * C: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\ - EVALUATE(N, Ro, C1, R2)\ + EVALUATE_MATRIX(N, Ro, C1, R2)\ std::cout << "Time Ro = C * R: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\ - EVALUATE(N, Ro, C1, C2)\ + EVALUATE_MATRIX(N, Ro, C1, C2)\ std::cout << "Time Ro = C * C: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\ - EVALUATE(N, Co, R1, R2)\ + EVALUATE_MATRIX(N, Co, R1, R2)\ std::cout << "Time Co = R * R: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\ - EVALUATE(N, Co, R1, C2)\ + EVALUATE_MATRIX(N, Co, R1, C2)\ std::cout << "Time Co = R * C: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\ - EVALUATE(N, Co, C1, R2)\ + EVALUATE_MATRIX(N, Co, C1, R2)\ std::cout << "Time Co = C * R: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\ - EVALUATE(N, Co, C1, C2)\ + EVALUATE_MATRIX(N, Co, C1, C2)\ std::cout << "Time Co = C * C: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N \ - << "us <-- this is the Eigen default!" << std::endl; + << "ns <-- this is the Eigen default!" << std::endl; @@ -69,6 +73,7 @@ int main() Matrix<double, 16, S - 3 + 1> results; clock_t t0, t1; + // All dynamic sizes { Matrix<double, Dynamic, Dynamic, RowMajor> R1, R2, Ro; Matrix<double, Dynamic, Dynamic, ColMajor> C1, C2, Co; @@ -78,51 +83,46 @@ int main() std::cout << "Timings for dynamic matrix product. R: row major matrix. C: column major matrix. " << s << "x" << s << " matrices." << std::endl; - INIT_ALL + INIT_MATRICES(s) EVALUATE_ALL } } -// N *= 1000; + // Statics, one by one { const int s = 3; std::cout << "Timings for static matrix product. R: row major matrix. C: column major matrix. " << s << "x" << s << " matrices." << std::endl; - Matrix<double, s, s, RowMajor> R1, R2, Ro; - Matrix<double, s, s, ColMajor> C1, C2, Co; - INIT_ALL + DECLARE_MATRICES(s) + INIT_MATRICES(s) EVALUATE_ALL } { const int s = 4; std::cout << "Timings for static matrix product. R: row major matrix. C: column major matrix. " << s << "x" << s << " matrices." << std::endl; - Matrix<double, s, s, RowMajor> R1, R2, Ro; - Matrix<double, s, s, ColMajor> C1, C2, Co; - INIT_ALL + DECLARE_MATRICES(s) + INIT_MATRICES(s) EVALUATE_ALL } -// N /= 100000; { const int s = 5; std::cout << "Timings for static matrix product. R: row major matrix. C: column major matrix. " << s << "x" << s << " matrices." << std::endl; - Matrix<double, s, s, RowMajor> R1, R2, Ro; - Matrix<double, s, s, ColMajor> C1, C2, Co; - INIT_ALL + DECLARE_MATRICES(s) + INIT_MATRICES(s) EVALUATE_ALL } { const int s = 6; std::cout << "Timings for static matrix product. R: row major matrix. C: column major matrix. " << s << "x" << s << " matrices." << std::endl; - Matrix<double, s, s, RowMajor> R1, R2, Ro; - Matrix<double, s, s, ColMajor> C1, C2, Co; - INIT_ALL + DECLARE_MATRICES(s) + INIT_MATRICES(s) EVALUATE_ALL } @@ -140,7 +140,9 @@ int main() } t1 = clock(); std::cout << "Time w = R * v: " << (double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl; + std::cout << "v norm change: " << 10*logl((long double)v.norm()/(long double)vn) << " dB" << std::endl; + v << 1,2,3; t0 = clock(); for (int i = 0; i < N; i++) { @@ -148,7 +150,7 @@ int main() } t1 = clock(); std::cout << "Time w = q * v: " << (double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl; - std::cout << "v norm change: " << 10*log((long double)v.norm()/(long double)vn) << " dB" << std::endl; + std::cout << "v norm change: " << 10*logl((long double)v.norm()/(long double)vn) << " dB" << std::endl; return 0; }