[libcxxabi] r222701 - [libcxxabi] Refactor test timing logic and disable by default.
Eric Fiselier
eric at efcs.ca
Mon Nov 24 14:38:58 PST 2014
Author: ericwf
Date: Mon Nov 24 16:38:57 2014
New Revision: 222701
URL: http://llvm.org/viewvc/llvm-project?rev=222701&view=rev
Log:
[libcxxabi] Refactor test timing logic and disable by default.
Summary:
When using LIT the timing output is entirely unused but introduces a dependency on `<chrono>`. When libc++ is built without a montonic clock this causes some of the tests to fail.
This patch factors out all of the timing logic into `support/timer.hpp` and disables it by default. To enable the timing you must define `LIBCXXABI_TIME_TESTS`.
Reviewers: mclow.lists, danalbert, jroelofs
Reviewed By: jroelofs
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D6391
Added:
libcxxabi/trunk/test/support/
libcxxabi/trunk/test/support/timer.hpp
Modified:
libcxxabi/trunk/test/dynamic_cast14.cpp
libcxxabi/trunk/test/dynamic_cast3.cpp
libcxxabi/trunk/test/dynamic_cast5.cpp
libcxxabi/trunk/test/dynamic_cast_stress.cpp
libcxxabi/trunk/test/lit.cfg
libcxxabi/trunk/test/test_demangle.cpp
Modified: libcxxabi/trunk/test/dynamic_cast14.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/dynamic_cast14.cpp?rev=222701&r1=222700&r2=222701&view=diff
==============================================================================
--- libcxxabi/trunk/test/dynamic_cast14.cpp (original)
+++ libcxxabi/trunk/test/dynamic_cast14.cpp Mon Nov 24 16:38:57 2014
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include <cassert>
+#include "support/timer.hpp"
namespace t1
{
@@ -2172,18 +2173,10 @@ void test()
} // t3
-#include <chrono>
-#include <iostream>
-
int main()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef Clock::time_point time_point;
- typedef std::chrono::duration<double, std::micro> 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";
}
Modified: libcxxabi/trunk/test/dynamic_cast3.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/dynamic_cast3.cpp?rev=222701&r1=222700&r2=222701&view=diff
==============================================================================
--- libcxxabi/trunk/test/dynamic_cast3.cpp (original)
+++ libcxxabi/trunk/test/dynamic_cast3.cpp Mon Nov 24 16:38:57 2014
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include <cassert>
+#include "support/timer.hpp"
/*
@@ -2406,15 +2407,9 @@ void test()
} // t41
-#include <chrono>
-#include <iostream>
-
int main()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef Clock::time_point time_point;
- typedef std::chrono::duration<double, std::micro> NS;
- time_point t0 = Clock::now();
+ timer t;
t1::test();
t2::test();
t3::test();
@@ -2456,6 +2451,4 @@ int main()
t39::test();
t40::test();
t41::test();
- time_point t1 = Clock::now();
- std::cout << NS(t1-t0).count() << " microseconds\n";
}
Modified: libcxxabi/trunk/test/dynamic_cast5.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/dynamic_cast5.cpp?rev=222701&r1=222700&r2=222701&view=diff
==============================================================================
--- libcxxabi/trunk/test/dynamic_cast5.cpp (original)
+++ libcxxabi/trunk/test/dynamic_cast5.cpp Mon Nov 24 16:38:57 2014
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include <cassert>
+#include "support/timer.hpp"
namespace t1
{
@@ -1298,15 +1299,10 @@ void test()
} // t9
-#include <chrono>
-#include <iostream>
int main()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef Clock::time_point time_point;
- typedef std::chrono::duration<double, std::micro> NS;
- time_point t0 = Clock::now();
+ timer t;
t1::test();
t2::test();
t3::test();
@@ -1316,6 +1312,4 @@ int main()
t7::test();
t8::test();
t9::test();
- time_point t1 = Clock::now();
- std::cout << NS(t1-t0).count() << " microseconds\n";
}
Modified: libcxxabi/trunk/test/dynamic_cast_stress.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/dynamic_cast_stress.cpp?rev=222701&r1=222700&r2=222701&view=diff
==============================================================================
--- libcxxabi/trunk/test/dynamic_cast_stress.cpp (original)
+++ libcxxabi/trunk/test/dynamic_cast_stress.cpp Mon Nov 24 16:38:57 2014
@@ -9,8 +9,7 @@
#include <cassert>
#include <tuple>
-#include <chrono>
-#include <iostream>
+#include "support/timer.hpp"
template <std::size_t Indx, std::size_t Depth>
struct C
@@ -50,17 +49,16 @@ struct A
void test()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef std::chrono::duration<double, std::micro> US;
const std::size_t Width = 10;
const std::size_t Depth = 5;
A<Width, Depth> a;
typedef B<Width/2, Depth> Destination;
// typedef A<Width, Depth> Destination;
- auto t0 = Clock::now();
- Destination* b = dynamic_cast<Destination*>((C<Width/2, 0>*)&a);
- auto t1 = Clock::now();
- std::cout << US(t1-t0).count() << " microseconds\n";
+ Destination *b = nullptr;
+ {
+ timer t;
+ b = dynamic_cast<Destination*>((C<Width/2, 0>*)&a);
+ }
assert(b != 0);
}
Modified: libcxxabi/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/lit.cfg?rev=222701&r1=222700&r2=222701&view=diff
==============================================================================
--- libcxxabi/trunk/test/lit.cfg (original)
+++ libcxxabi/trunk/test/lit.cfg Mon Nov 24 16:38:57 2014
@@ -237,6 +237,10 @@ if link_flags_str is not None:
# Configure extra compiler flags.
+# Always disable timed test when using LIT since the output gets lost and since
+# using the timer requires <chrono> as a dependancy.
+compile_flags += ['-DLIBCXXABI_NO_TIMER']
+
san = lit_config.params.get('llvm_use_sanitizer', None)
if san is None:
san = getattr(config, 'llvm_use_sanitizer', None)
Added: libcxxabi/trunk/test/support/timer.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/support/timer.hpp?rev=222701&view=auto
==============================================================================
--- libcxxabi/trunk/test/support/timer.hpp (added)
+++ libcxxabi/trunk/test/support/timer.hpp Mon Nov 24 16:38:57 2014
@@ -0,0 +1,46 @@
+#ifndef TIMER_HPP
+#define TIMER_HPP
+
+// Define LIBCXXABI_NO_TIMER to disable testing with a timer.
+#ifndef LIBCXXABI_NO_TIMER
+
+#include <chrono>
+#include <iostream>
+
+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<MicroSeconds>(end - m_start);
+ std::cout << us.count() << " microseconds\n";
+ }
+
+private:
+ TimePoint m_start;
+};
+
+#else /* LIBCXXABI_NO_TIMER */
+
+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
Modified: libcxxabi/trunk/test/test_demangle.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_demangle.cpp?rev=222701&r1=222700&r2=222701&view=diff
==============================================================================
--- libcxxabi/trunk/test/test_demangle.cpp (original)
+++ libcxxabi/trunk/test/test_demangle.cpp Mon Nov 24 16:38:57 2014
@@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
+#include "support/timer.hpp"
#include <iostream>
#include <string>
#include <cstdlib>
#include <cxxabi.h>
#include <cassert>
-#include <chrono>
// Is long double fp80? (Only x87 extended double has 64-bit mantissa)
#define LDBL_FP80 (__LDBL_MANT_DIG__ == 64)
@@ -29664,14 +29664,12 @@ void test2()
int main()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef std::chrono::duration<double> 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)
More information about the cfe-commits
mailing list