Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / math / differential_testing / Timer.cpp
blob979196ae6b8359946fe68916e3b91b177ac30139
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "Timer.h"
11 #include <chrono>
12 #include <fstream>
14 namespace LIBC_NAMESPACE {
15 namespace testing {
17 struct TimerImplementation {
18 std::chrono::high_resolution_clock::time_point Start;
19 std::chrono::high_resolution_clock::time_point End;
22 Timer::Timer() : Impl(new TimerImplementation) {}
24 Timer::~Timer() { delete reinterpret_cast<TimerImplementation *>(Impl); }
26 void Timer::start() {
27 auto T = reinterpret_cast<TimerImplementation *>(Impl);
28 T->Start = std::chrono::high_resolution_clock::now();
31 void Timer::stop() {
32 auto T = reinterpret_cast<TimerImplementation *>(Impl);
33 T->End = std::chrono::high_resolution_clock::now();
36 uint64_t Timer::nanoseconds() const {
37 auto T = reinterpret_cast<TimerImplementation *>(Impl);
38 return std::chrono::nanoseconds(T->End - T->Start).count();
41 } // namespace testing
42 } // namespace LIBC_NAMESPACE