Index: test/dynamic_cast14.cpp =================================================================== --- test/dynamic_cast14.cpp +++ test/dynamic_cast14.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include +#include "support/timer.hpp" namespace t1 { @@ -2172,18 +2173,10 @@ } // t3 -#include -#include - int main() { - typedef std::chrono::high_resolution_clock Clock; - typedef Clock::time_point time_point; - typedef std::chrono::duration NS; - time_point t0 = Clock::now(); + timer t; t1::test(); t2::test(); t3::test(); - time_point t1 = Clock::now(); - std::cout << NS(t1-t0).count() << " microseconds\n"; } Index: test/dynamic_cast3.cpp =================================================================== --- test/dynamic_cast3.cpp +++ test/dynamic_cast3.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include +#include "support/timer.hpp" /* @@ -2406,15 +2407,9 @@ } // t41 -#include -#include - int main() { - typedef std::chrono::high_resolution_clock Clock; - typedef Clock::time_point time_point; - typedef std::chrono::duration NS; - time_point t0 = Clock::now(); + timer t; t1::test(); t2::test(); t3::test(); @@ -2456,6 +2451,4 @@ t39::test(); t40::test(); t41::test(); - time_point t1 = Clock::now(); - std::cout << NS(t1-t0).count() << " microseconds\n"; } Index: test/dynamic_cast5.cpp =================================================================== --- test/dynamic_cast5.cpp +++ test/dynamic_cast5.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include +#include "support/timer.hpp" namespace t1 { @@ -1298,15 +1299,10 @@ } // t9 -#include -#include int main() { - typedef std::chrono::high_resolution_clock Clock; - typedef Clock::time_point time_point; - typedef std::chrono::duration NS; - time_point t0 = Clock::now(); + timer t; t1::test(); t2::test(); t3::test(); @@ -1316,6 +1312,4 @@ t7::test(); t8::test(); t9::test(); - time_point t1 = Clock::now(); - std::cout << NS(t1-t0).count() << " microseconds\n"; } Index: test/dynamic_cast_stress.cpp =================================================================== --- test/dynamic_cast_stress.cpp +++ test/dynamic_cast_stress.cpp @@ -9,8 +9,7 @@ #include #include -#include -#include +#include "support/timer.hpp" template struct C @@ -50,17 +49,16 @@ void test() { - typedef std::chrono::high_resolution_clock Clock; - typedef std::chrono::duration US; const std::size_t Width = 10; const std::size_t Depth = 5; A a; typedef B Destination; // typedef A Destination; - auto t0 = Clock::now(); - Destination* b = dynamic_cast((C*)&a); - auto t1 = Clock::now(); - std::cout << US(t1-t0).count() << " microseconds\n"; + Destination *b = nullptr; + { + timer t; + b = dynamic_cast((C*)&a); + } assert(b != 0); } Index: test/support/timer.hpp =================================================================== --- /dev/null +++ test/support/timer.hpp @@ -0,0 +1,46 @@ +#ifndef TIMER_HPP +#define TIMER_HPP + +// Defined LIBCXXABI_TIME_TESTS to run the timer in the tests. +#ifdef LIBCXXABI_TIME_TESTS + +#include +#include + +class timer +{ + typedef std::chrono::high_resolution_clock Clock; + typedef Clock::time_point TimePoint; + typedef std::chrono::microseconds MicroSeconds; +public: + timer() : m_start(Clock::now()) {} + + timer(timer const &) = delete; + timer & operator=(timer const &) = delete; + + ~timer() + { + using std::chrono::duration_cast; + TimePoint end = Clock::now(); + MicroSeconds us = duration_cast(end - m_start); + std::cout << us.count() << " microseconds\n"; + } + +private: + TimePoint m_start; +}; + +#else /* LIBCXXABI_TIME_TESTS */ + +class timer +{ +public: + timer() {} + timer(timer const &) = delete; + timer & operator=(timer const &) = delete; + ~timer() {} +}; + +#endif /* LIBCXXABI_TIME_TESTS */ + +#endif /* TIMER_HPP */ \ No newline at end of file Index: test/test_demangle.cpp =================================================================== --- test/test_demangle.cpp +++ test/test_demangle.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include "support/timer.hpp" // Is long double fp80? (Only x87 extended double has 64-bit mantissa) #define LDBL_FP80 (__LDBL_MANT_DIG__ == 64) @@ -29664,14 +29664,12 @@ int main() { - typedef std::chrono::high_resolution_clock Clock; - typedef std::chrono::duration sec; - Clock::time_point t0 = Clock::now(); - test(); - test2(); - Clock::time_point t1 = Clock::now(); - std::cout << sec(t1-t0).count() << " seconds for test\n"; - std::cout << N / sec(t1-t0).count() / 1000000. << " million symbols per second\n"; + std::cout << "Testing " << N << " symbols." << std::endl; + { + timer t; + test(); + test2(); + } #if 0 std::string input; while (std::cin)