44 lines · cpp
1//===-- Timer.cpp --------------------------------------------------------===//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#include "Timer.h"10#include "src/__support/macros/config.h"11 12#include <chrono>13#include <fstream>14 15namespace LIBC_NAMESPACE_DECL {16namespace testing {17 18struct TimerImplementation {19 std::chrono::high_resolution_clock::time_point Start;20 std::chrono::high_resolution_clock::time_point End;21};22 23Timer::Timer() : Impl(new TimerImplementation) {}24 25Timer::~Timer() { delete reinterpret_cast<TimerImplementation *>(Impl); }26 27void Timer::start() {28 auto T = reinterpret_cast<TimerImplementation *>(Impl);29 T->Start = std::chrono::high_resolution_clock::now();30}31 32void Timer::stop() {33 auto T = reinterpret_cast<TimerImplementation *>(Impl);34 T->End = std::chrono::high_resolution_clock::now();35}36 37uint64_t Timer::nanoseconds() const {38 auto T = reinterpret_cast<TimerImplementation *>(Impl);39 return std::chrono::nanoseconds(T->End - T->Start).count();40}41 42} // namespace testing43} // namespace LIBC_NAMESPACE_DECL44