Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxxabi / test / support / timer.h
blob27dc5f6a6d032f1007dbe86f24ed5e9705a83752
1 //===----------------------------------------------------------------------===////
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===////
9 #ifndef TIMER_H
10 #define TIMER_H
12 // Define LIBCXXABI_USE_TIMER to enable testing with a timer.
13 #if defined(LIBCXXABI_USE_TIMER)
15 #include <chrono>
16 #include <cstdio>
18 class timer
20 typedef std::chrono::high_resolution_clock Clock;
21 typedef Clock::time_point TimePoint;
22 typedef std::chrono::microseconds MicroSeconds;
23 public:
24 timer() : m_start(Clock::now()) {}
26 timer(timer const &) = delete;
27 timer & operator=(timer const &) = delete;
29 ~timer()
31 using std::chrono::duration_cast;
32 TimePoint end = Clock::now();
33 MicroSeconds us = duration_cast<MicroSeconds>(end - m_start);
34 std::printf("%d microseconds\n", us.count());
37 private:
38 TimePoint m_start;
41 #else /* LIBCXXABI_USE_TIMER */
43 class timer
45 public:
46 timer() {}
47 timer(timer const &) = delete;
48 timer & operator=(timer const &) = delete;
49 ~timer() {}
52 #endif /* LIBCXXABI_USE_TIMER */
54 #endif /* TIMER_H */