mirror of
https://github.com/boostorg/move.git
synced 2025-07-30 20:37:13 +02:00
- Make sure testsuite passes with "exception-handling=off". Requires using a custom mini-timer since Boost.Timer depends on Boost.Chrono, and Boost.Chrono's dll does not compile without exceptions.
This commit is contained in:
@ -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_); }
|
||||
|
214
include/boost/move/detail/nsec_clock.hpp
Normal file
214
include/boost/move/detail/nsec_clock.hpp
Normal file
@ -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 <boost/config.hpp>
|
||||
|
||||
|
||||
# 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 <boost/winapi/time.hpp>
|
||||
#include <boost/winapi/timers.hpp>
|
||||
#include <boost/winapi/get_last_error.hpp>
|
||||
#include <boost/winapi/error_codes.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
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<boost::uint64_t>((nanosecs_per_tic) * pcount.QuadPart);
|
||||
}
|
||||
|
||||
}} //namespace boost { namespace move_detail {
|
||||
|
||||
#elif defined(BOOST_MOVE_DETAIL_MAC_API)
|
||||
|
||||
#include <mach/mach_time.h> // 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<boost::uint64_t>
|
||||
( static_cast<double>(count)*(static_cast<double>(info.numer) / info.denom);
|
||||
}
|
||||
|
||||
#elif defined(BOOST_MOVE_DETAIL_POSIX_API)
|
||||
|
||||
#include <time.h>
|
||||
|
||||
# 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
|
@ -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
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <boost/move/algo/adaptive_merge.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
template<class T>
|
||||
@ -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;
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <boost/move/algo/adaptive_sort.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
template<class T>
|
||||
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;
|
||||
|
@ -18,16 +18,16 @@
|
||||
#include <boost/container/vector.hpp> //boost::container::vector
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <boost/move/unique_ptr.hpp>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <boost/move/detail/nsec_clock.hpp>
|
||||
|
||||
#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<order_perf_type>(101,1);
|
||||
measure_all<order_perf_type>(101,5);
|
||||
@ -324,11 +322,6 @@ int main()
|
||||
measure_all<order_perf_type>(10000001,0);
|
||||
#endif //#ifndef BENCH_MERGE_SHORT
|
||||
#endif //#ifdef NDEBUG
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -17,11 +17,11 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/move/unique_ptr.hpp>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <boost/move/detail/nsec_clock.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user