timeCholesky.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* ----------------------------------------------------------------------------
  2. * GTSAM Copyright 2010, Georgia Tech Research Corporation,
  3. * Atlanta, Georgia 30332-0415
  4. * All Rights Reserved
  5. * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
  6. * See LICENSE for the license information
  7. * -------------------------------------------------------------------------- */
  8. /**
  9. * @file timeCholesky.cpp
  10. * @brief time Cholesky factorization
  11. * @author Frank Dellaert
  12. * @date March 4, 2016
  13. */
  14. #include <gtsam/base/cholesky.h>
  15. #include <time.h>
  16. #include <iostream>
  17. #include <iomanip> // std::setprecision
  18. using namespace std;
  19. using namespace gtsam;
  20. //#define TERNARY
  21. int main() {
  22. Matrix top = (Matrix(7,7) <<
  23. 4.0375, 3.4584, 3.5735, 2.4815, 2.1471, 2.7400, 2.2063,
  24. 0., 4.7267, 3.8423, 2.3624, 2.8091, 2.9579, 2.5914,
  25. 0., 0., 5.1600, 2.0797, 3.4690, 3.2419, 2.9992,
  26. 0., 0., 0., 1.8786, 1.0535, 1.4250, 1.3347,
  27. 0., 0., 0., 0., 3.0788, 2.6283, 2.3791,
  28. 0., 0., 0., 0., 0., 2.9227, 2.4056,
  29. 0., 0., 0., 0., 0., 0., 2.5776).finished();
  30. Matrix ABC(100,100);
  31. ABC.topLeftCorner<7,7>() = top;
  32. cout << setprecision(3);
  33. size_t n = 100000;
  34. for (size_t nFrontal = 1; nFrontal <= 7; nFrontal++) {
  35. auto timeLog = clock();
  36. for (size_t i = 0; i < n; i++) {
  37. Matrix RSL(ABC);
  38. choleskyPartial(RSL, nFrontal);
  39. }
  40. auto timeLog2 = clock();
  41. auto seconds = (double)(timeLog2 - timeLog) / CLOCKS_PER_SEC;
  42. cout << "partialCholesky " << nFrontal << ": ";
  43. auto ms = ((double)seconds * 1000000 / n);
  44. cout << ms << " ms, " << ms/nFrontal << " ms/dim" << endl;
  45. }
  46. return 0;
  47. }