diff --git a/example/doc_file_descriptor.cpp b/example/doc_file_descriptor.cpp index 1c7f28f..bfc5a57 100644 --- a/example/doc_file_descriptor.cpp +++ b/example/doc_file_descriptor.cpp @@ -33,7 +33,10 @@ class file_descriptor public: explicit file_descriptor(const char *filename) //Constructor : os_descr_(operating_system_open_file(filename)) - { if(!os_descr_) throw std::runtime_error("file not found"); } + { + //=if(!os_descr_) + //=throw std::runtime_error("file not found"); + } ~file_descriptor() //Destructor { if(os_descr_) operating_system_close_file(os_descr_); } diff --git a/include/boost/move/detail/nsec_clock.hpp b/include/boost/move/detail/nsec_clock.hpp new file mode 100644 index 0000000..1919062 --- /dev/null +++ b/include/boost/move/detail/nsec_clock.hpp @@ -0,0 +1,214 @@ +// This code is based on Timer and Chrono code. Thanks to authors: +// +// Boost.Timer: +// Copyright Beman Dawes 1994-2007, 2011 +// +// Boost.Chrono: +// Copyright Beman Dawes 2008 +// Copyright 2009-2010 Vicente J. Botet Escriba +// +// Simplified and modified to be able to support exceptionless (-fno-exceptions). +// Boost.Timer depends on Boost.Chorno wich uses boost::throw_exception. +// And Boost.Chrono DLLs don't build in Win32 as there is no +// boost::throw_exception(std::exception const&) implementation +// in Boost.Chrono: +// +// Copyright 2020 Ion Gaztanaga +// +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +//----------------------------------------------------------------------------// +// Windows // +//----------------------------------------------------------------------------// +#ifndef BOOST_MOVE_DETAIL_NSEC_CLOCK_HPP +#define BOOST_MOVE_DETAIL_NSEC_CLOCK_HPP + +#include + + +# if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) +# define BOOST_MOVE_DETAIL_WINDOWS_API +# elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) +# define BOOST_MOVE_DETAIL_MAC_API +# else +# define BOOST_MOVE_DETAIL_POSIX_API +# endif + +#if defined(BOOST_MOVE_DETAIL_WINDOWS_API) + +#include +#include +#include +#include +#include + +namespace boost { namespace move_detail { + +inline boost::uint64_t nsec_clock() BOOST_NOEXCEPT +{ + boost::winapi::LARGE_INTEGER_ freq; + if ( !boost::winapi::QueryPerformanceFrequency( &freq ) ) + { + BOOST_ASSERT(0 && "Boost::Move - get_nanosecs_per_tic Internal Error"); + return 0u; + } + + double nanosecs_per_tic = double(1000000000.0L / freq.QuadPart); + + boost::winapi::LARGE_INTEGER_ pcount; + if ( nanosecs_per_tic <= 0.0L ) + { + BOOST_ASSERT(0 && "Boost::Move - get_nanosecs_per_tic Internal Error"); + return 0u; + } + unsigned times=0; + while ( ! boost::winapi::QueryPerformanceCounter( &pcount ) ) + { + if ( ++times > 3 ) + { + BOOST_ASSERT(0 && "Boost::Move - QueryPerformanceCounter Internal Error"); + return 0u; + } + } + + return static_cast((nanosecs_per_tic) * pcount.QuadPart); +} + +}} //namespace boost { namespace move_detail { + +#elif defined(BOOST_MOVE_DETAIL_MAC_API) + +#include // mach_absolute_time, mach_timebase_info_data_t + +inline boost::uint64_t nsec_clock() BOOST_NOEXCEPT +{ + boost::uint64_t count = ::mach_absolute_time(); + + mach_timebase_info_data_t info; + mach_timebase_info(&info); + return static_cast + ( static_cast(count)*(static_cast(info.numer) / info.denom); +} + +#elif defined(BOOST_MOVE_DETAIL_POSIX_API) + +#include + +# if defined(CLOCK_MONOTONIC_PRECISE) //BSD +# define BOOST_MOVE_DETAIL_CLOCK_MONOTONIC CLOCK_MONOTONIC_PRECISE +# elif defined(CLOCK_MONOTONIC_RAW) //Linux +# define BOOST_MOVE_DETAIL_CLOCK_MONOTONIC CLOCK_MONOTONIC_RAW +# elif defined(CLOCK_HIGHRES) //Solaris +# define BOOST_MOVE_DETAIL_CLOCK_MONOTONIC CLOCK_HIGHRES +# elif defined(CLOCK_MONOTONIC) //POSIX (AIX, BSD, Linux, Solaris) +# define BOOST_MOVE_DETAIL_CLOCK_MONOTONIC CLOCK_MONOTONIC +# else +# error "No high resolution steady clock in your system, please provide a patch" +# endif + +inline boost::uint64_t nsec_clock() BOOST_NOEXCEPT +{ + struct timespec count; + ::clock_gettime(BOOST_MOVE_DETAIL_CLOCK_MONOTONIC, &count); + boost::uint64_t r = count.tv_sec; + r *= 1000000000U; + r += count.tv_nsec; + return r; +} + +#endif // POSIX + +namespace boost { namespace move_detail { + +typedef boost::uint64_t nanosecond_type; + +struct cpu_times +{ + nanosecond_type wall; + nanosecond_type user; + nanosecond_type system; + + void clear() { wall = user = system = 0; } +}; + + +inline void get_cpu_times(boost::move_detail::cpu_times& current) +{ + current.wall = nsec_clock(); +} + + +class cpu_timer +{ + public: + + // constructor + cpu_timer() BOOST_NOEXCEPT { start(); } + + // observers + bool is_stopped() const BOOST_NOEXCEPT { return m_is_stopped; } + cpu_times elapsed() const BOOST_NOEXCEPT; // does not stop() + + // actions + void start() BOOST_NOEXCEPT; + void stop() BOOST_NOEXCEPT; + void resume() BOOST_NOEXCEPT; + + private: + cpu_times m_times; + bool m_is_stopped; +}; + + +// cpu_timer ---------------------------------------------------------------------// + +inline void cpu_timer::start() BOOST_NOEXCEPT +{ + m_is_stopped = false; + get_cpu_times(m_times); +} + +inline void cpu_timer::stop() BOOST_NOEXCEPT +{ + if (is_stopped()) + return; + m_is_stopped = true; + + cpu_times current; + get_cpu_times(current); + m_times.wall = (current.wall - m_times.wall); + m_times.user = (current.user - m_times.user); + m_times.system = (current.system - m_times.system); +} + +inline cpu_times cpu_timer::elapsed() const BOOST_NOEXCEPT +{ + if (is_stopped()) + return m_times; + cpu_times current; + get_cpu_times(current); + current.wall -= m_times.wall; + current.user -= m_times.user; + current.system -= m_times.system; + return current; +} + +inline void cpu_timer::resume() BOOST_NOEXCEPT +{ + if (is_stopped()) + { + cpu_times current (m_times); + start(); + m_times.wall -= current.wall; + m_times.user -= current.user; + m_times.system -= current.system; + } +} + + + +} // namespace move_detail +} // namespace boost + +#endif //BOOST_MOVE_DETAIL_NSEC_CLOCK_HPP diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 472517b..2ce67bb 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -15,7 +15,7 @@ rule test_all for local fileb in [ glob *.cpp ] { - all_rules += [ run $(fileb) /boost/timer//boost_timer + all_rules += [ run $(fileb) : # additional args : # test-files : # requirements diff --git a/test/adaptive_merge_test.cpp b/test/adaptive_merge_test.cpp index 1a64707..1b6ebd3 100644 --- a/test/adaptive_merge_test.cpp +++ b/test/adaptive_merge_test.cpp @@ -22,6 +22,7 @@ #include #include +#include template @@ -60,7 +61,7 @@ bool test_random_shuffled(std::size_t const element_count, std::size_t const num if (!is_order_type_ordered(elements.get(), element_count)) { std::cout << "\n ERROR\n"; - throw int(0); + std::abort(); } } return true; diff --git a/test/adaptive_sort_test.cpp b/test/adaptive_sort_test.cpp index 973dd4c..512138b 100644 --- a/test/adaptive_sort_test.cpp +++ b/test/adaptive_sort_test.cpp @@ -22,6 +22,7 @@ #include #include +#include template bool test_random_shuffled(std::size_t const element_count, std::size_t const num_keys, std::size_t const num_iter) @@ -53,7 +54,7 @@ bool test_random_shuffled(std::size_t const element_count, std::size_t const num if (!is_order_type_ordered(elements.get(), element_count)) { std::cout << "\n ERROR\n"; - throw int(0); + std::abort(); } } return true; diff --git a/test/bench_merge.cpp b/test/bench_merge.cpp index 2ef3440..d676b7e 100644 --- a/test/bench_merge.cpp +++ b/test/bench_merge.cpp @@ -18,16 +18,16 @@ #include //boost::container::vector #include +#include #include -#include +#include #include "order_type.hpp" #include "random_shuffle.hpp" -using boost::timer::cpu_timer; -using boost::timer::cpu_times; -using boost::timer::nanosecond_type; +using boost::move_detail::cpu_timer; +using boost::move_detail::nanosecond_type; void print_stats(const char *str, boost::ulong_long_type element_count) { @@ -255,9 +255,8 @@ bool measure_all(std::size_t L, std::size_t NK) elements = original_elements; res = res && measure_algo(elements.data(), L, split_pos,StdInplaceMerge, prev_clock); // - - if(!res) - throw int(0); + if (!res) + std::abort(); return res; } @@ -267,7 +266,6 @@ bool measure_all(std::size_t L, std::size_t NK) int main() { - try{ #ifndef BENCH_SORT_UNIQUE_VALUES measure_all(101,1); measure_all(101,5); @@ -324,11 +322,6 @@ int main() measure_all(10000001,0); #endif //#ifndef BENCH_MERGE_SHORT #endif //#ifdef NDEBUG - } - catch(...) - { - return 1; - } return 0; } diff --git a/test/bench_sort.cpp b/test/bench_sort.cpp index 11aba35..59c6548 100644 --- a/test/bench_sort.cpp +++ b/test/bench_sort.cpp @@ -17,11 +17,11 @@ #include #include -#include +#include +#include -using boost::timer::cpu_timer; -using boost::timer::cpu_times; -using boost::timer::nanosecond_type; +using boost::move_detail::cpu_timer; +using boost::move_detail::nanosecond_type; #include "order_type.hpp" #include "random_shuffle.hpp" @@ -304,9 +304,9 @@ bool measure_all(std::size_t L, std::size_t NK) //prev_clock = back_clock; //elements = original_elements; //res = res && measure_algo(elements.data(), L,SlowStableSort, prev_clock); - // + if(!res) - throw int(0); + std::abort(); return res; }