1 //===-- Timer.cpp --------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
14 namespace LIBC_NAMESPACE
{
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
); }
27 auto T
= reinterpret_cast<TimerImplementation
*>(Impl
);
28 T
->Start
= std::chrono::high_resolution_clock::now();
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