2016-01-20 06:07:10 +08:00
|
|
|
//===----------------------------------------------------------------------===////
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-01-20 06:07:10 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===////
|
|
|
|
|
2019-08-13 03:19:29 +08:00
|
|
|
#ifndef TIMER_H
|
|
|
|
#define TIMER_H
|
2014-11-25 06:38:57 +08:00
|
|
|
|
2021-10-13 02:15:33 +08:00
|
|
|
// Define LIBCXXABI_USE_TIMER to enable testing with a timer.
|
|
|
|
#if defined(LIBCXXABI_USE_TIMER)
|
2014-11-25 06:38:57 +08:00
|
|
|
|
|
|
|
#include <chrono>
|
2020-10-14 03:47:31 +08:00
|
|
|
#include <cstdio>
|
2014-11-25 06:38:57 +08:00
|
|
|
|
|
|
|
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);
|
2020-10-14 03:47:31 +08:00
|
|
|
std::printf("%d microseconds\n", us.count());
|
2014-11-25 06:38:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TimePoint m_start;
|
|
|
|
};
|
|
|
|
|
2021-10-13 02:15:33 +08:00
|
|
|
#else /* LIBCXXABI_USE_TIMER */
|
2014-11-25 06:38:57 +08:00
|
|
|
|
|
|
|
class timer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
timer() {}
|
|
|
|
timer(timer const &) = delete;
|
|
|
|
timer & operator=(timer const &) = delete;
|
|
|
|
~timer() {}
|
|
|
|
};
|
|
|
|
|
2021-10-13 02:15:33 +08:00
|
|
|
#endif /* LIBCXXABI_USE_TIMER */
|
2014-11-25 06:38:57 +08:00
|
|
|
|
2019-08-13 03:19:29 +08:00
|
|
|
#endif /* TIMER_H */
|