|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59212 - sandbox/chrono/libs/chrono/test
From: vicente.botet_at_[hidden]
Date: 2010-01-21 18:25:35
Author: viboes
Date: 2010-01-21 18:25:34 EST (Thu, 21 Jan 2010)
New Revision: 59212
URL: http://svn.boost.org/trac/boost/changeset/59212
Log:
Boost.Chrono: Version 0.3.2,
* added test on suspendable clok
Added:
sandbox/chrono/libs/chrono/test/test_suspendable_clock.cpp (contents, props changed)
Text files modified:
sandbox/chrono/libs/chrono/test/Jamfile.v2 | 7 +++++++
sandbox/chrono/libs/chrono/test/stopclock_constructor_overload_test.cpp | 2 +-
2 files changed, 8 insertions(+), 1 deletions(-)
Modified: sandbox/chrono/libs/chrono/test/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/chrono/test/Jamfile.v2 (original)
+++ sandbox/chrono/libs/chrono/test/Jamfile.v2 2010-01-21 18:25:34 EST (Thu, 21 Jan 2010)
@@ -88,9 +88,16 @@
[ run run_timer_test.cpp : : : <library>/boost/system//boost_system : run_timer_test_dll ]
;
+ #test-suite "suspendable_clock"
+ # :
+ #[ run test_suspendable_clock.cpp : : : <library>/boost/thread//boost_thread <link>static ]
+ #[ run test_suspendable_clock.cpp : : : <library>/boost/thread//boost_thread <library>/boost/system//boost_system : test_suspendable_clock_dll ]
+ # ;
+
test-suite "stopwatch"
:
[ run ../example/stopwatch_example.cpp : : : <link>static ]
+ [ run ../example/stopwatch_example.cpp : : : <link>static ]
[ run ../example/stopwatch_example.cpp : : : <library>/boost/system//boost_system : stopwatch_example_dll ]
[ run ../example/scoped_stopwatch_example.cpp : : : <library>/boost/thread//boost_thread <link>static ]
[ run ../example/scoped_stopwatch_example.cpp : : : <library>/boost/thread//boost_thread <library>/boost/system//boost_system : scoped_stopwatch_example_dll ]
Modified: sandbox/chrono/libs/chrono/test/stopclock_constructor_overload_test.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/stopclock_constructor_overload_test.cpp (original)
+++ sandbox/chrono/libs/chrono/test/stopclock_constructor_overload_test.cpp 2010-01-21 18:25:34 EST (Thu, 21 Jan 2010)
@@ -1,4 +1,4 @@
-// boost run_timer_test.cpp -----------------------------------------------------//
+// boost stopclock_constructor_overload_test.cpp -----------------------------------------------------//
// Copyright Beman Dawes 2006, 2008
// Copyright 2009 Vicente J. Botet Escriba
Added: sandbox/chrono/libs/chrono/test/test_suspendable_clock.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/test_suspendable_clock.cpp 2010-01-21 18:25:34 EST (Thu, 21 Jan 2010)
@@ -0,0 +1,117 @@
+// test_system_clock.cpp ----------------------------------------------------------//
+
+// Copyright 2010 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/chrono.hpp>
+#include <boost/chrono/suspendable_clock.hpp>
+#include <boost/type_traits.hpp>
+
+#include <iostream>
+
+using namespace boost::chrono;
+
+void test_system_clock()
+{
+ std::cout << "suspendable_clock<system_clock> test" << std::endl;
+ suspendable_clock<system_clock>::duration delay = milliseconds(5);
+ suspendable_clock<system_clock>::time_point start = suspendable_clock<system_clock>::now();
+ while (suspendable_clock<system_clock>::now() - start <= delay)
+ ;
+ suspendable_clock<system_clock>::time_point stop = suspendable_clock<system_clock>::now();
+ suspendable_clock<system_clock>::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+ start = suspendable_clock<system_clock>::now();
+ stop = suspendable_clock<system_clock>::now();
+ std::cout << "suspendable_clock<system_clock> resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+ start = suspendable_clock<system_clock>::now();
+ suspendable_clock<system_clock>::suspend();
+ system_clock::duration delay3 = milliseconds(50);
+ system_clock::time_point start3 = system_clock::now();
+ while (system_clock::now() - start3 <= delay3)
+ ;
+ system_clock::time_point stop3 = system_clock::now();
+ stop = suspendable_clock<system_clock>::now();
+ std::cout << "system_clock 50ms: " << nanoseconds(stop3-start3).count() << " nanoseconds\n";
+ std::cout << "suspendable_clock<system_clock> 50ms: " << nanoseconds(stop-start).count() << " nanoseconds\n";
+ suspendable_clock<system_clock>::resume();
+
+}
+
+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();
+ 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