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

source code of libc/test/src/math/performance_testing/Timer.cpp