1 // (C) Copyright 2013 Andrey
2 // (C) Copyright 2013 Vicente J. Botet Escriba
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // This performance test is based on the performance test provided by maxim.yegorushkin
9 // at https://svn.boost.org/trac/boost/ticket/7422
11 #define BOOST_THREAD_USES_CHRONO
14 #include <boost/thread/lock_types.hpp>
15 #include <boost/thread/thread_only.hpp>
16 #include <boost/chrono/chrono_io.hpp>
18 #include <boost/thread/shared_mutex.hpp>
20 using namespace boost
;
23 const int cycles
= 10000;
28 while (++cycle
< cycles
)
30 shared_lock
<shared_mutex
> lock(mtx
);
37 while (++cycle
< cycles
)
39 unique_lock
<shared_mutex
> lock(mtx
);
45 boost::chrono::high_resolution_clock::duration
best_time(std::numeric_limits
<boost::chrono::high_resolution_clock::duration::rep
>::max
BOOST_PREVENT_MACRO_SUBSTITUTION ());
46 for (int i
=100; i
>0; --i
) {
47 boost::chrono::high_resolution_clock clock
;
48 boost::chrono::high_resolution_clock::time_point s1
= clock
.now();
62 boost::chrono::high_resolution_clock::time_point f1
= clock
.now();
63 //std::cout << " Time spent:" << (f1 - s1) << std::endl;
64 best_time
= std::min
BOOST_PREVENT_MACRO_SUBSTITUTION (best_time
, f1
- s1
);
67 std::cout
<< "Best Time spent:" << best_time
<< std::endl
;
68 std::cout
<< "Time spent/cycle:" << best_time
/cycles
/3 << std::endl
;