time_measure.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //----------------------------------------------------------------------------
  2. /// @file time_measure.hpp
  3. /// @brief This class is done in order to simplify the time measure in the
  4. /// benchmaark programs
  5. ///
  6. /// @author Copyright (c) 2010 2015 Francisco José Tapia ([email protected] )\n
  7. /// Distributed under the Boost Software License, Version 1.0.\n
  8. /// ( See accompanyingfile LICENSE_1_0.txt or copy at
  9. /// http://www.boost.org/LICENSE_1_0.txt )
  10. /// @version 0.1
  11. ///
  12. /// @remarks
  13. //-----------------------------------------------------------------------------
  14. #ifndef __BOOST_SORT_PARALLEL_TOOLS_TIME_MEASURE_HPP
  15. #define __BOOST_SORT_PARALLEL_TOOLS_TIME_MEASURE_HPP
  16. #include <ciso646>
  17. #include <chrono>
  18. namespace boost
  19. {
  20. namespace sort
  21. {
  22. namespace common
  23. {
  24. namespace chrn = std::chrono;
  25. //
  26. //***************************************************************************
  27. // D E F I N I T I O N S
  28. //***************************************************************************
  29. typedef chrn::steady_clock::time_point time_point;
  30. //
  31. //---------------------------------------------------------------------------
  32. // function : now
  33. /// @brief return the time system in a internal format ( steady_clock)
  34. /// @return time in steady_clock format
  35. //---------------------------------------------------------------------------
  36. inline time_point now ( ) { return chrn::steady_clock::now( ); };
  37. //
  38. //---------------------------------------------------------------------------
  39. // function : subtract_time
  40. /// @brief return the time in double format
  41. /// @param [in] t1 : first time in time_point format
  42. /// @param [in] t2 : second time in time_point format
  43. /// @return time in seconds of the difference of t1 - t2
  44. //---------------------------------------------------------------------------
  45. inline double subtract_time ( const time_point & t1, const time_point & t2 )
  46. { //------------------------ begin ---------------------------------
  47. chrn::duration<double> time_span =
  48. chrn::duration_cast < chrn::duration < double > > ( t1 - t2 );
  49. return time_span.count( );
  50. };
  51. //***************************************************************************
  52. };// End namespace benchmark
  53. };// End namespace sort
  54. };// End namespace boost
  55. //***************************************************************************
  56. #endif