|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r66340 - sandbox/chrono/libs/chrono/example
From: vicente.botet_at_[hidden]
Date: 2010-11-01 18:41:19
Author: viboes
Date: 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
New Revision: 66340
URL: http://svn.boost.org/trac/boost/changeset/66340
Log:
Chrono: Refactor tests
Added:
sandbox/chrono/libs/chrono/example/chrono_accuracy_test.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/chrono_unit_test.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/clock_name.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/clock_name.hpp (contents, props changed)
sandbox/chrono/libs/chrono/example/explore_limits.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/manipulate_clock_object.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/miscellaneous.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/test_clock.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/test_clock2.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/test_duration.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/test_minmax.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/test_special_values.cpp (contents, props changed)
sandbox/chrono/libs/chrono/example/test_thread_clock.cpp (contents, props changed)
Added: sandbox/chrono/libs/chrono/example/chrono_accuracy_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/chrono_accuracy_test.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,102 @@
+// boost run_timer_test.cpp -----------------------------------------------------//
+
+// Copyright Beman Dawes 2006, 2008
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/chrono for documentation.
+
+#include <boost/chrono/process_times.hpp>
+#include <boost/chrono/timer.hpp>
+#include <cstdlib> // for atol()
+#include <iostream>
+#include <sstream>
+#include <locale>
+#include <ctime>
+#include <cmath> // for sqrt(), used to burn time
+
+using boost::chrono::run_timer;
+using boost::system::error_code;
+
+#include <boost/detail/lightweight_test.hpp>
+
+namespace
+{
+ typedef boost::chrono::nanoseconds ns;
+
+ // accuracy test
+ void accuracy_test( int argc, char * argv[] )
+ {
+ long timeout_in_secs = 1;
+ if ( argc > 1 ) timeout_in_secs = std::atol( argv[1] );
+ std::cout << "accuracy test for " << timeout_in_secs << " second(s)...";
+
+ std::clock_t timeout_in_clock_t = std::clock();
+ timeout_in_clock_t += (timeout_in_secs * CLOCKS_PER_SEC);
+
+ boost::chrono::system_timer sys;
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ boost::chrono::monotonic_timer mono;
+#endif
+ boost::chrono::high_resolution_timer hires;
+ boost::chrono::process_timer process;
+
+ std::clock_t now;
+ do
+ {
+ now = std::clock();
+ } while ( now < timeout_in_clock_t );
+
+ boost::chrono::system_timer::duration sys_dur = sys.elapsed();
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ boost::chrono::monotonic_timer::duration mono_dur = mono.elapsed();
+#endif
+ boost::chrono::high_resolution_timer::duration hires_dur = hires.elapsed();
+ boost::chrono::process_times times;
+ process.elapsed( times );
+
+ std::cout << std::endl;
+
+ ns timeout_in_nanoseconds( static_cast<long long>(timeout_in_secs) * 1000000000LL );
+
+ // Allow 20% leeway. Particularly on Linux, there seems to be a large discrepancy
+ // between std::clock() and higher resolution clocks.
+ ns maximum_delta ( static_cast<long long>(timeout_in_nanoseconds.count() * 0.20 ) );
+
+ std::cout << timeout_in_nanoseconds.count() << " timeout_in_nanoseconds\n";
+ std::cout << maximum_delta.count() << " maximum_delta\n";
+
+ std::cout << sys_dur.count() << " sys_dur\n";
+
+ BOOST_TEST( sys_dur > timeout_in_nanoseconds - maximum_delta
+ && sys_dur < timeout_in_nanoseconds + maximum_delta );
+
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ std::cout << mono_dur.count() << " mono_dur\n";
+
+ BOOST_TEST( mono_dur > timeout_in_nanoseconds - maximum_delta
+ && mono_dur < timeout_in_nanoseconds + maximum_delta );
+#endif
+
+ std::cout << hires_dur.count() << " hires_dur\n";
+
+ BOOST_TEST( hires_dur > timeout_in_nanoseconds - maximum_delta
+ && hires_dur < timeout_in_nanoseconds + maximum_delta );
+
+ std::cout << times.real.count() << " times.real\n";
+
+ BOOST_TEST( times.real > timeout_in_nanoseconds - maximum_delta
+ && times.real < timeout_in_nanoseconds + maximum_delta );
+ }
+
+}
+
+int main( int argc, char * argv[] )
+{
+ accuracy_test( argc, argv );
+
+ return boost::report_errors();
+}
+
Added: sandbox/chrono/libs/chrono/example/chrono_unit_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/chrono_unit_test.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,31 @@
+// chrono_unit_test.cpp ----------------------------------------------------//
+
+// Copyright 2008 Beman Dawes
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness
+
+#include <boost/chrono/chrono.hpp>
+#include <iostream>
+
+
+int main()
+{
+ boost::chrono::nanoseconds nanosecs;
+ boost::chrono::microseconds microsecs;
+ boost::chrono::milliseconds millisecs;
+ boost::chrono::seconds secs;
+ boost::chrono::minutes mins;
+ boost::chrono::hours hrs;
+
+ std::time_t sys_time
+ = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now());
+
+ std::cout
+ << "system_clock::to_time_t(system_clock::now()) is "
+ << std::asctime(std::gmtime(&sys_time)) << std::endl;
+
+ return 0;
+}
Added: sandbox/chrono/libs/chrono/example/clock_name.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/clock_name.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,20 @@
+// stopclock_perf.cpp ---------------------------------------------------//
+
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/chrono for documentation.
+
+#include "clock_name.hpp"
+#include <iostream>
+
+int main()
+{
+ std::cout << name<boost::chrono::system_clock>::apply() << '\n';
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ std::cout << name<boost::chrono::monotonic_clock>::apply() << '\n';
+#endif
+ std::cout << name<boost::chrono::high_resolution_clock>::apply() << '\n';
+}
Added: sandbox/chrono/libs/chrono/example/clock_name.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/clock_name.hpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,68 @@
+// stopclock_perf.cpp ---------------------------------------------------//
+
+// Copyright 2009 Vicente J. Botet Escriba
+// Copyright 2009 Howard Hinnant
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/chrono for documentation.
+
+#ifndef BOOST_CHRONO_CLOCK_NAME_HPP
+#define BOOST_CHRONO_CLOCK_NAME_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+template <typename Clock,
+ bool = boost::is_same<Clock, boost::chrono::system_clock>::value,
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ bool = boost::is_same<Clock, boost::chrono::monotonic_clock>::value,
+#else
+ bool = false,
+#endif
+ bool = boost::is_same<Clock, boost::chrono::high_resolution_clock>::value
+ >
+struct name;
+
+template <typename Clock>
+struct name<Clock, false, false, false> {
+ static const char* apply() { return "unknown clock";}
+};
+
+template <typename Clock>
+struct name<Clock, true, false, false> {
+ static const char* apply() { return "system_clock";}
+};
+
+template <typename Clock>
+struct name<Clock, false, true, false> {
+ static const char* apply() { return "monotonic_clock";}
+};
+
+template <typename Clock>
+struct name<Clock, false, false, true> {
+ static const char* apply() { return "high_resolution_clock";}
+};
+
+template <typename Clock>
+struct name<Clock, false, true, true> {
+ static const char* apply() { return "monotonic_clock and high_resolution_clock";}
+};
+
+template <typename Clock>
+struct name<Clock, true, false, true> {
+ static const char* apply() { return "system_clock and high_resolution_clock";}
+};
+
+template <typename Clock>
+struct name<Clock, true, true, false> {
+ static const char* apply() { return "system_clock and monotonic_clock";}
+};
+
+template <typename Clock>
+struct name<Clock, true, true, true> {
+ static const char* apply() { return "system_clock, monotonic_clock and high_resolution_clock";}
+};
+
+#endif
Added: sandbox/chrono/libs/chrono/example/explore_limits.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/explore_limits.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,60 @@
+// explore_limits.cpp ----------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+/*
+This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which
+was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+using namespace boost::chrono;
+
+
+void explore_limits()
+{
+ typedef duration<long long, boost::ratio_multiply<boost::ratio<24*3652425,10000>,
+ hours::period>::type> Years;
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ monotonic_clock::time_point t1( Years(250));
+ monotonic_clock::time_point t2(-Years(250));
+#else
+ system_clock::time_point t1( Years(250));
+ system_clock::time_point t2(-Years(250));
+#endif
+ // nanosecond resolution is likely to overflow. "up cast" to microseconds.
+ // The "up cast" trades precision for range.
+ microseconds d = time_point_cast<microseconds>(t1) - time_point_cast<microseconds>(t2);
+ std::cout << d.count() << " microseconds\n";
+}
+
+
+int main()
+{
+ explore_limits();
+ return 0;
+}
+
Added: sandbox/chrono/libs/chrono/example/manipulate_clock_object.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/manipulate_clock_object.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,61 @@
+// manipulate_clock_object.cpp ----------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+/*
+This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which
+was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+using namespace boost::chrono;
+
+#if defined _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4100)
+#endif
+void manipulate_clock_object(system_clock clock)
+#if defined _MSC_VER
+#pragma warning(pop)
+#endif
+{
+ system_clock::duration delay = milliseconds(5);
+ system_clock::time_point start = clock.now();
+
+ while ((clock.now() - start) <= delay) {}
+
+ system_clock::time_point stop = clock.now();
+ system_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+}
+
+
+int main()
+{
+ manipulate_clock_object(system_clock());
+ return 0;
+}
+
Added: sandbox/chrono/libs/chrono/example/miscellaneous.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/miscellaneous.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,157 @@
+// miscellaneous.cpp ----------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+/*
+This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which
+was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+// miscellaneous tests and demos:
+
+#include <cassert>
+#include <iostream>
+
+using namespace boost::chrono;
+
+void physics_function(duration<double> d)
+{
+ std::cout << "d = " << d.count() << '\n';
+}
+
+void drive_physics_function()
+{
+ physics_function(nanoseconds(3));
+ physics_function(hours(3));
+ physics_function(duration<double>(2./3));
+ std::cout.precision(16);
+ physics_function( hours(3) + nanoseconds(-3) );
+}
+
+void test_range()
+{
+ using namespace boost::chrono;
+ hours h1 = hours(24 * ( 365 * 292 + 292/4));
+ nanoseconds n1 = h1 + nanoseconds(1);
+ nanoseconds delta = n1 - h1;
+ std::cout << "292 years of hours = " << h1.count() << "hr\n";
+ std::cout << "Add a nanosecond = " << n1.count() << "ns\n";
+ std::cout << "Find the difference = " << delta.count() << "ns\n";
+}
+
+void test_extended_range()
+{
+ using namespace boost::chrono;
+ hours h1 = hours(24 * ( 365 * 244000 + 244000/4));
+ /*auto*/ microseconds u1 = h1 + microseconds(1);
+ /*auto*/ microseconds delta = u1 - h1;
+ std::cout << "244,000 years of hours = " << h1.count() << "hr\n";
+ std::cout << "Add a microsecond = " << u1.count() << "us\n";
+ std::cout << "Find the difference = " << delta.count() << "us\n";
+}
+
+template <class Rep, class Period>
+void inspect_duration(boost::chrono::duration<Rep, Period> d, const std::string& name)
+{
+ typedef boost::chrono::duration<Rep, Period> Duration;
+ std::cout << "********* " << name << " *********\n";
+ std::cout << "The period of " << name << " is " << (double)Period::num/Period::den << " seconds.\n";
+ std::cout << "The frequency of " << name << " is " << (double)Period::den/Period::num << " Hz.\n";
+ std::cout << "The representation is ";
+ if (boost::is_floating_point<Rep>::value)
+ {
+ std::cout << "floating point\n";
+ std::cout << "The precision is the most significant ";
+ std::cout << std::numeric_limits<Rep>::digits10 << " decimal digits.\n";
+ }
+ else if (boost::is_integral<Rep>::value)
+ {
+ std::cout << "integral\n";
+ d = Duration(Rep(1));
+ boost::chrono::duration<double> dsec = d;
+ std::cout << "The precision is " << dsec.count() << " seconds.\n";
+ }
+ else
+ {
+ std::cout << "a class type\n";
+ d = Duration(Rep(1));
+ boost::chrono::duration<double> dsec = d;
+ std::cout << "The precision is " << dsec.count() << " seconds.\n";
+ }
+ d = Duration((std::numeric_limits<Rep>::max)());
+ using namespace boost::chrono;
+ using namespace std;
+ typedef duration<double, boost::ratio_multiply<boost::ratio<24*3652425,10000>, hours::period>::type> Years;
+ Years years = d;
+ std::cout << "The range is +/- " << years.count() << " years.\n";
+ std::cout << "sizeof(" << name << ") = " << sizeof(d) << '\n';
+}
+
+void inspect_all()
+{
+ using namespace boost::chrono;
+ std::cout.precision(6);
+ inspect_duration(nanoseconds(), "nanoseconds");
+ inspect_duration(microseconds(), "microseconds");
+ inspect_duration(milliseconds(), "milliseconds");
+ inspect_duration(seconds(), "seconds");
+ inspect_duration(minutes(), "minutes");
+ inspect_duration(hours(), "hours");
+ inspect_duration(duration<double>(), "duration<double>");
+}
+
+void test_milliseconds()
+{
+ using namespace boost::chrono;
+ milliseconds ms(250);
+ ms += milliseconds(1);
+ milliseconds ms2(150);
+ milliseconds msdiff = ms - ms2;
+ if (msdiff == milliseconds(101))
+ std::cout << "success\n";
+ else
+ std::cout << "failure: " << msdiff.count() << '\n';
+}
+
+int main()
+{
+ using namespace boost;
+ drive_physics_function();
+ test_range();
+ test_extended_range();
+ inspect_all();
+ test_milliseconds();
+ inspect_duration(common_type<duration<double>, hours, microseconds>::type(),
+ "common_type<duration<double>, hours, microseconds>::type");
+ duration<double, boost::milli> d = milliseconds(3) * 2.5;
+ inspect_duration(milliseconds(3) * 2.5, "milliseconds(3) * 2.5");
+ std::cout << d.count() << '\n';
+// milliseconds ms(3.5); // doesn't compile
+// std::cout << "milliseconds ms(3.5) doesn't compile\n";
+ return 0;
+}
+
Added: sandbox/chrono/libs/chrono/example/test_clock.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/test_clock.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,172 @@
+// test_system_clock.cpp ----------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+/*
+This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which
+was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+#include "clock_name.hpp"
+
+using namespace boost::chrono;
+
+template <typename Clock>
+void test_clock()
+{
+ std::cout << "\n"<< name<Clock>::apply() << " test" << std::endl;
+{
+ typename Clock::duration delay = milliseconds(5);
+ typename Clock::time_point start = Clock::now();
+ while (Clock::now() - start <= delay)
+ ;
+ typename Clock::time_point stop = Clock::now();
+ //typename Clock::duration elapsed = stop - start;
+ std::cout << "5 milliseconds paused " << nanoseconds(stop - start).count() << " nanoseconds\n";
+}
+{
+ typename Clock::time_point start = Clock::now();
+ typename Clock::time_point stop;
+ std::size_t count=1;
+ while ((stop=Clock::now()) == start) {
+ ++count;
+ }
+ //typename Clock::duration elapsed = stop - start;
+ std::cout << "After " << count << " trials, elapsed time " << nanoseconds(stop - start).count() << " nanoseconds\n";
+
+ start = Clock::now();
+ for (std::size_t c=count; c>0; --c) {
+ stop=Clock::now();;
+ }
+ std::cout << "After " << count << " trials, elapsed time " << nanoseconds(stop - start).count() << " nanoseconds\n";
+
+
+}
+{
+ typename Clock::time_point start = Clock::now();
+ typename Clock::time_point stop = Clock::now();
+ std::cout << "Resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+}
+}
+
+void test_system_clock()
+{
+ std::cout << "system_clock test" << std::endl;
+ system_clock::duration delay = milliseconds(5);
+ system_clock::time_point start = system_clock::now();
+ while (system_clock::now() - start <= delay)
+ ;
+ system_clock::time_point stop = system_clock::now();
+ system_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+ start = system_clock::now();
+ stop = system_clock::now();
+ std::cout << "system_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+}
+
+void test_monotonic_clock()
+{
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ std::cout << "monotonic_clock test" << std::endl;
+ monotonic_clock::duration delay = milliseconds(5);
+ monotonic_clock::time_point start = monotonic_clock::now();
+ while (monotonic_clock::now() - start <= delay)
+ ;
+ monotonic_clock::time_point stop = monotonic_clock::now();
+ monotonic_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+ start = monotonic_clock::now();
+ stop = monotonic_clock::now();
+ std::cout << "monotonic_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+#endif
+}
+void test_hi_resolution_clock()
+{
+ std::cout << "high_resolution_clock test" << std::endl;
+ high_resolution_clock::duration delay = milliseconds(5);
+ high_resolution_clock::time_point start = high_resolution_clock::now();
+ while (high_resolution_clock::now() - start <= delay)
+ ;
+ high_resolution_clock::time_point stop = high_resolution_clock::now();
+ high_resolution_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+ start = high_resolution_clock::now();
+ stop = high_resolution_clock::now();
+ std::cout << "high_resolution_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+}
+
+//void test_mixed_clock()
+//{
+// std::cout << "mixed clock test" << std::endl;
+// high_resolution_clock::time_point hstart = high_resolution_clock::now();
+// std::cout << "Add 5 milliseconds to a high_resolution_clock::time_point\n";
+// monotonic_clock::time_point mend = hstart + milliseconds(5);
+// bool b = hstart == mend;
+// system_clock::time_point sstart = system_clock::now();
+// std::cout << "Subtracting system_clock::time_point from monotonic_clock::time_point doesn't compile\n";
+//// mend - sstart; // doesn't compile
+// std::cout << "subtract high_resolution_clock::time_point from monotonic_clock::time_point"
+// " and add that to a system_clock::time_point\n";
+// system_clock::time_point send = sstart + duration_cast<system_clock::duration>(mend - hstart);
+// std::cout << "subtract two system_clock::time_point's and output that in microseconds:\n";
+// microseconds ms = send - sstart;
+// std::cout << ms.count() << " microseconds\n";
+//}
+//
+//void test_c_mapping()
+//{
+// std::cout << "C map test\n";
+// using namespace boost::chrono;
+// system_clock::time_point t1 = system_clock::now();
+// std::time_t c_time = system_clock::to_time_t(t1);
+// std::tm* tmptr = std::localtime(&c_time);
+// std::cout << "It is now " << tmptr->tm_hour << ':' << tmptr->tm_min << ':' << tmptr->tm_sec << ' '
+// << tmptr->tm_year + 1900 << '-' << tmptr->tm_mon + 1 << '-' << tmptr->tm_mday << '\n';
+// c_time = std::mktime(tmptr);
+// system_clock::time_point t2 = system_clock::from_time_t(c_time);
+// microseconds ms = t1 - t2;
+// std::cout << "Round-tripping through the C interface truncated the precision by " << ms.count() << " microseconds\n";
+//}
+
+
+int main()
+{
+ test_system_clock();
+ test_monotonic_clock();
+ test_hi_resolution_clock();
+ //test_mixed_clock();
+ test_clock<system_clock>();
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ test_clock<monotonic_clock>();
+#endif
+ test_clock<high_resolution_clock>();
+
+
+
+ return 0;
+}
+
Added: sandbox/chrono/libs/chrono/example/test_clock2.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/test_clock2.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,210 @@
+// test_system_clock.cpp ----------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+/*
+This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which
+was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+#include "clock_name.hpp"
+
+namespace boost {
+ namespace detail_chrono {
+ class monotonic_clock {};
+ class system_clock {};
+ }
+ namespace chrono {
+ namespace chrono_detail {
+ using namespace detail_chrono;
+ struct has_monotonic_clock {
+ template< class T > static char sfinae( typename T::rep );
+ template< class > static int sfinae( ... );
+
+ enum { value = sizeof sfinae< monotonic_clock >( 0 ) == sizeof(char) };
+ };
+ struct has_system_clock {
+ template< class T > static char sfinae( typename T::rep );
+ template< class > static int sfinae( ... );
+
+ enum { value = sizeof sfinae< system_clock >( 0 ) == sizeof(char) };
+ };
+ }
+ struct has_monotonic_clock
+ : integral_constant<bool, chrono_detail::has_monotonic_clock::value> {};
+ struct has_system_clock
+ : integral_constant<bool, chrono_detail::has_system_clock::value> {};
+ }
+
+}
+
+BOOST_STATIC_ASSERT(boost::chrono::has_system_clock::value);
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+BOOST_STATIC_ASSERT(boost::chrono::has_monotonic_clock::value);
+#else
+BOOST_STATIC_ASSERT(!boost::chrono::has_monotonic_clock::value);
+#endif
+
+using namespace boost::chrono;
+using namespace boost;
+
+template <typename Clock>
+void test_clock()
+{
+ std::cout << "\n"<< name<Clock>::apply() << " test" << std::endl;
+{
+ typename Clock::duration delay = milliseconds(5);
+ typename Clock::time_point start = Clock::now();
+ while (Clock::now() - start <= delay)
+ ;
+ typename Clock::time_point stop = Clock::now();
+ //typename Clock::duration elapsed = stop - start;
+ std::cout << "5 milliseconds paused " << nanoseconds(stop - start).count() << " nanoseconds\n";
+}
+{
+ typename Clock::time_point start = Clock::now();
+ typename Clock::time_point stop;
+ std::size_t count=1;
+ while ((stop=Clock::now()) == start) {
+ ++count;
+ }
+ //typename Clock::duration elapsed = stop - start;
+ std::cout << "After " << count << " trials, elapsed time " << nanoseconds(stop - start).count() << " nanoseconds\n";
+
+ start = Clock::now();
+ for (std::size_t c=count; c>0; --c) {
+ stop=Clock::now();;
+ }
+ std::cout << "After " << count << " trials, elapsed time " << nanoseconds(stop - start).count() << " nanoseconds\n";
+
+
+}
+{
+ typename Clock::time_point start = Clock::now();
+ typename Clock::time_point stop = Clock::now();
+ std::cout << "Resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+}
+}
+
+void test_system_clock()
+{
+ std::cout << "system_clock test" << std::endl;
+ //~ system_clock clk;
+ chrono::system_clock::duration delay = milliseconds(5);
+ chrono::system_clock::time_point start = system_clock::now();
+ while (chrono::system_clock::now() - start <= delay)
+ ;
+ chrono::system_clock::time_point stop = system_clock::now();
+ chrono::system_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+ start = chrono::system_clock::now();
+ stop = chrono::system_clock::now();
+ std::cout << "system_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+}
+
+void test_monotonic_clock()
+{
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ std::cout << "monotonic_clock test" << std::endl;
+ monotonic_clock::duration delay = milliseconds(5);
+ monotonic_clock::time_point start = monotonic_clock::now();
+ while (monotonic_clock::now() - start <= delay)
+ ;
+ monotonic_clock::time_point stop = monotonic_clock::now();
+ monotonic_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+ start = monotonic_clock::now();
+ stop = monotonic_clock::now();
+ std::cout << "monotonic_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+#endif
+}
+void test_hi_resolution_clock()
+{
+ std::cout << "high_resolution_clock test" << std::endl;
+ high_resolution_clock::duration delay = milliseconds(5);
+ high_resolution_clock::time_point start = high_resolution_clock::now();
+ while (high_resolution_clock::now() - start <= delay)
+ ;
+ high_resolution_clock::time_point stop = high_resolution_clock::now();
+ high_resolution_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+ start = high_resolution_clock::now();
+ stop = high_resolution_clock::now();
+ std::cout << "high_resolution_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+}
+
+//void test_mixed_clock()
+//{
+// std::cout << "mixed clock test" << std::endl;
+// high_resolution_clock::time_point hstart = high_resolution_clock::now();
+// std::cout << "Add 5 milliseconds to a high_resolution_clock::time_point\n";
+// monotonic_clock::time_point mend = hstart + milliseconds(5);
+// bool b = hstart == mend;
+// system_clock::time_point sstart = system_clock::now();
+// std::cout << "Subtracting system_clock::time_point from monotonic_clock::time_point doesn't compile\n";
+//// mend - sstart; // doesn't compile
+// std::cout << "subtract high_resolution_clock::time_point from monotonic_clock::time_point"
+// " and add that to a system_clock::time_point\n";
+// system_clock::time_point send = sstart + duration_cast<system_clock::duration>(mend - hstart);
+// std::cout << "subtract two system_clock::time_point's and output that in microseconds:\n";
+// microseconds ms = send - sstart;
+// std::cout << ms.count() << " microseconds\n";
+//}
+//
+//void test_c_mapping()
+//{
+// std::cout << "C map test\n";
+// using namespace boost::chrono;
+// system_clock::time_point t1 = system_clock::now();
+// std::time_t c_time = system_clock::to_time_t(t1);
+// std::tm* tmptr = std::localtime(&c_time);
+// std::cout << "It is now " << tmptr->tm_hour << ':' << tmptr->tm_min << ':' << tmptr->tm_sec << ' '
+// << tmptr->tm_year + 1900 << '-' << tmptr->tm_mon + 1 << '-' << tmptr->tm_mday << '\n';
+// c_time = std::mktime(tmptr);
+// system_clock::time_point t2 = system_clock::from_time_t(c_time);
+// microseconds ms = t1 - t2;
+// std::cout << "Round-tripping through the C interface truncated the precision by " << ms.count() << " microseconds\n";
+//}
+
+
+int main()
+{
+ test_system_clock();
+ test_monotonic_clock();
+ test_hi_resolution_clock();
+ //test_mixed_clock();
+ test_clock<system_clock>();
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ test_clock<monotonic_clock>();
+#endif
+ test_clock<high_resolution_clock>();
+
+
+
+ return 0;
+}
+
Added: sandbox/chrono/libs/chrono/example/test_duration.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/test_duration.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,199 @@
+// test_duration.cpp ----------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+/*
+This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which
+was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+#include <cassert>
+#include <boost/chrono/chrono.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+template <class Rep, class Period>
+void inspect_duration(boost::chrono::duration<Rep, Period> d, const std::string& name)
+{
+ typedef boost::chrono::duration<Rep, Period> Duration;
+ std::cout << "********* " << name << " *********\n";
+ std::cout << "The period of " << name << " is " << (double)Period::num/Period::den << " seconds.\n";
+ std::cout << "The frequency of " << name << " is " << (double)Period::den/Period::num << " Hz.\n";
+ std::cout << "The representation is ";
+ if (boost::is_floating_point<Rep>::value)
+ {
+ std::cout << "floating point\n";
+ std::cout << "The precision is the most significant ";
+ std::cout << std::numeric_limits<Rep>::digits10 << " decimal digits.\n";
+ }
+ else if (boost::is_integral<Rep>::value)
+ {
+ std::cout << "integral\n";
+ d = Duration(Rep(1));
+ boost::chrono::duration<double> dsec = d;
+ std::cout << "The precision is " << dsec.count() << " seconds.\n";
+ }
+ else
+ {
+ std::cout << "a class type\n";
+ d = Duration(Rep(1));
+ boost::chrono::duration<double> dsec = d;
+ std::cout << "The precision is " << dsec.count() << " seconds.\n";
+ }
+ d = Duration((std::numeric_limits<Rep>::max)());
+ using namespace boost::chrono;
+ using namespace std;
+ typedef duration<double, boost::ratio_multiply<boost::ratio<24*3652425,10000>, hours::period>::type> Years;
+ Years years = d;
+ std::cout << "The range is +/- " << years.count() << " years.\n";
+ std::cout << "sizeof(" << name << ") = " << sizeof(d) << '\n';
+}
+
+void inspect_all()
+{
+ using namespace boost::chrono;
+ std::cout.precision(6);
+ inspect_duration(nanoseconds(), "nanoseconds");
+ inspect_duration(microseconds(), "microseconds");
+ inspect_duration(milliseconds(), "milliseconds");
+ inspect_duration(seconds(), "seconds");
+ inspect_duration(minutes(), "minutes");
+ inspect_duration(hours(), "hours");
+ inspect_duration(duration<double>(), "duration<double>");
+}
+
+
+
+using namespace boost::chrono;
+void test_duration_division()
+{
+ typedef boost::common_type<boost::chrono::hours::rep, boost::chrono::minutes::rep>::type h_min_rep;
+ h_min_rep r3 = hours(3) / minutes(5);
+ std::cout << r3 << '\n';
+ std::cout << hours(3) / minutes(5) << '\n';
+ std::cout << hours(3) / milliseconds(5) << '\n';
+ std::cout << milliseconds(5) / hours(3) << '\n';
+ std::cout << hours(1) / milliseconds(1) << '\n';
+}
+
+void test_duration_multiply()
+{
+ hours h15= 5 * hours(3);
+ hours h6= hours(3) *2;
+}
+
+void f(duration<double> d, double res) // accept floating point seconds
+{
+ // d.count() == 3.e-6 when passed microseconds(3)
+ assert(d.count()==res);
+}
+
+void g(nanoseconds d, boost::intmax_t res)
+{
+ // d.count() == 3000 when passed microseconds(3)
+ std::cout << d.count() << " " <<res << std::endl;
+ assert(d.count()==res);
+}
+
+template <class Rep, class Period>
+void tmpl(duration<Rep, Period> d, boost::intmax_t res)
+{
+ // convert d to nanoseconds, rounding up if it is not an exact conversion
+ nanoseconds ns = duration_cast<nanoseconds>(d);
+ if (ns < d)
+ ++ns;
+ // ns.count() == 333333334 when passed 1/3 of a floating point second
+ assert(ns.count()==res);
+}
+
+template <class Period>
+void tmpl2(duration<long long, Period> d, boost::intmax_t res)
+{
+ // convert d to nanoseconds, rounding up if it is not an exact conversion
+ nanoseconds ns = duration_cast<nanoseconds>(d);
+ if (ns < d)
+ ++ns;
+ // ns.count() == 333333334 when passed 333333333333 picoseconds
+ assert(ns.count()==res);
+}
+
+
+
+int main()
+{
+ minutes m1(3); // m1 stores 3
+ minutes m2(2); // m2 stores 2
+ minutes m3 = m1 + m2; // m3 stores 5
+ assert(m3.count()==5);
+
+ microseconds us1(3); // us1 stores 3
+ microseconds us2(2); // us2 stores 2
+ microseconds us3 = us1 + us2; // us3 stores 5
+ assert(us3.count()==5);
+
+ microseconds us4 = m3 + us3; // us4 stores 300000005
+ assert(us4.count()==300000005);
+ microseconds us5 = m3; // us4 stores 300000000
+ assert(us5.count()==300000000);
+
+ //minutes m4 = m3 + us3; // won't compile
+
+ minutes m4 = duration_cast<minutes>(m3 + us3); // m4.count() == 5
+ assert(m4.count()==5);
+
+ typedef duration<double, boost::ratio<60> > dminutes;
+ dminutes dm4 = m3 + us3; // dm4.count() == 5.000000083333333
+ assert(dm4.count()==5.000000083333333);
+
+ f(microseconds(3), 0.000003);
+ g(microseconds(3), 3000);
+ duration<double> s(1./3); // 1/3 of a second
+ g(duration_cast<nanoseconds>(s), 333333333); // round towards zero in conversion to nanoseconds
+ //f(s); // does not compile
+ tmpl(duration<double>(1./3), 333333334);
+ tmpl2(duration<long long, boost::pico>(333333333333LL), 333333334); // About 1/3 of a second worth of picoseconds
+
+ //f(3,3); // Will not compile, 3 is not implicitly convertible to any `duration`
+ //g(3,3); // Will not compile, 3 is not implicitly convertible to any `duration`
+ //tmpl(3,3); // Will not compile, 3 is not implicitly convertible to any `duration`
+ //tmpl2(3,3); // Will not compile, 3 is not implicitly convertible to any `duration`
+
+ {
+ double r = double(milliseconds(3) / milliseconds(3));
+ std::cout << r << '\n';
+
+ duration<double, boost::milli> d = milliseconds(3) * 2.5;
+ duration<double, boost::milli> d2 = 2.5 * milliseconds(3) ;
+ duration<double, boost::milli> d3 = milliseconds(3) / 2.5;
+ duration<double, boost::milli> d4 = milliseconds(3) + milliseconds(5) ;
+ inspect_duration(milliseconds(3) * 2.5, "milliseconds(3) * 2.5");
+ std::cout << d.count() << '\n';
+// milliseconds ms(3.5); // doesn't compile
+ std::cout << "milliseconds ms(3.5) doesn't compile\n";
+ }
+
+ test_duration_division();
+ test_duration_multiply();
+ return 0;
+}
+
Added: sandbox/chrono/libs/chrono/example/test_minmax.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/test_minmax.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,17 @@
+// test_duration.cpp ----------------------------------------------------------//
+
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#if !defined(__GNUC__)
+
+#define min(A,B) ((A)<(B)?(A):(B))
+#define max(A,B) ((A)>(B)?(A):(B))
+
+#include <boost/chrono/chrono.hpp>
+
+#endif
+
+
Added: sandbox/chrono/libs/chrono/example/test_special_values.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/test_special_values.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,51 @@
+// test_special_values.cpp ----------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+/*
+This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which
+was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+using namespace boost::chrono;
+
+void test_special_values()
+{
+ std::cout << "duration<unsigned>::min().count() = " << ((duration<unsigned>::min)()).count() << '\n';
+ std::cout << "duration<unsigned>::zero().count() = " << duration<unsigned>::zero().count() << '\n';
+ std::cout << "duration<unsigned>::max().count() = " << ((duration<unsigned>::max)()).count() << '\n';
+ std::cout << "duration<int>::min().count() = " << ((duration<int>::min)()).count() << '\n';
+ std::cout << "duration<int>::zero().count() = " << duration<int>::zero().count() << '\n';
+ std::cout << "duration<int>::max().count() = " << ((duration<int>::max)()).count() << '\n';
+}
+
+int main()
+{
+ test_special_values();
+ return 0;
+}
+
Added: sandbox/chrono/libs/chrono/example/test_thread_clock.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/test_thread_clock.cpp 2010-11-01 18:41:13 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,41 @@
+// test_thread_clock.cpp ----------------------------------------------------------//
+
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#include <boost/chrono/thread_clock.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+using namespace boost::chrono;
+
+void test_thread_clock()
+{
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+ std::cout << "thread_clock test" << std::endl;
+ thread_clock::duration delay = milliseconds(5);
+ thread_clock::time_point start = thread_clock::now();
+ while (thread_clock::now() - start <= delay)
+ ;
+ thread_clock::time_point stop = thread_clock::now();
+ thread_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+ start = thread_clock::now();
+ stop = thread_clock::now();
+ std::cout << "thread_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+#else
+ std::cout << "thread_clock not available\n";
+#endif
+}
+
+
+int main()
+{
+ test_thread_clock();
+ return 0;
+}
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk