55 lines · c
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-exception6//7//===----------------------------------------------------------------------===////8 9#ifndef TIMER_H10#define TIMER_H11 12// Define LIBCXXABI_USE_TIMER to enable testing with a timer.13#if defined(LIBCXXABI_USE_TIMER)14 15#include <chrono>16#include <cstdio>17 18class timer19{20 typedef std::chrono::high_resolution_clock Clock;21 typedef Clock::time_point TimePoint;22 typedef std::chrono::microseconds MicroSeconds;23public:24 timer() : m_start(Clock::now()) {}25 26 timer(timer const &) = delete;27 timer & operator=(timer const &) = delete;28 29 ~timer()30 {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());35 }36 37private:38 TimePoint m_start;39};40 41#else /* LIBCXXABI_USE_TIMER */42 43class timer44{45public:46 timer() {}47 timer(timer const &) = delete;48 timer & operator=(timer const &) = delete;49 ~timer() {}50};51 52#endif /* LIBCXXABI_USE_TIMER */53 54#endif /* TIMER_H */55