get_seconds.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_GET_SECONDS_H
  9. #define IGL_GET_SECONDS_H
  10. #include "igl_inline.h"
  11. #define IGL_TICTOC_LAMBDA \
  12. const auto & tictoc = []() \
  13. { \
  14. static double t_start = igl::get_seconds(); \
  15. double diff = igl::get_seconds()-t_start; \
  16. t_start += diff; \
  17. return diff; \
  18. };
  19. namespace igl
  20. {
  21. /// Current time in seconds
  22. ///
  23. /// @return the current time in seconds since epoch
  24. ///
  25. /// #### Example:
  26. /// \code{cpp}
  27. /// const auto & tictoc = []()
  28. /// {
  29. /// static double t_start = igl::get_seconds();
  30. /// double diff = igl::get_seconds()-t_start;
  31. /// t_start += diff;
  32. /// return diff;
  33. /// };
  34. /// tictoc();
  35. /// ... // part 1
  36. /// cout<<"part 1: "<<tictoc()<<endl;
  37. /// ... // part 2
  38. /// cout<<"part 2: "<<tictoc()<<endl;
  39. /// ... // etc
  40. /// \endcode
  41. IGL_INLINE double get_seconds();
  42. }
  43. #ifndef IGL_STATIC_LIBRARY
  44. # include "get_seconds.cpp"
  45. #endif
  46. #endif