time_measure.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 (fjtapia@gmail.com )\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 <chrono>
  17. namespace boost
  18. {
  19. namespace sort
  20. {
  21. namespace common
  22. {
  23. namespace chrn = std::chrono;
  24. //
  25. //***************************************************************************
  26. // D E F I N I T I O N S
  27. //***************************************************************************
  28. typedef chrn::steady_clock::time_point time_point;
  29. time_point now ( );
  30. double subtract_time ( const time_point & t1, const time_point & t2 );
  31. //
  32. //---------------------------------------------------------------------------
  33. // function : now
  34. /// @brief return the time system in a internal format ( steady_clock)
  35. /// @return time in steady_clock format
  36. //---------------------------------------------------------------------------
  37. time_point now ( ) { return chrn::steady_clock::now( ); };
  38. //
  39. //---------------------------------------------------------------------------
  40. // function : subtract_time
  41. /// @brief return the time in double format
  42. /// @param [in] t1 : first time in time_point format
  43. /// @param [in] t2 : second time in time_point format
  44. /// @return time in seconds of the difference of t1 - t2
  45. //---------------------------------------------------------------------------
  46. double subtract_time ( const time_point & t1, const time_point & t2 )
  47. { //------------------------ begin ---------------------------------
  48. chrn::duration<double> time_span =
  49. chrn::duration_cast < chrn::duration < double > > ( t1 - t2 );
  50. return time_span.count( );
  51. };
  52. //***************************************************************************
  53. };// End namespace benchmark
  54. };// End namespace sort
  55. };// End namespace boost
  56. //***************************************************************************
  57. #endif