Grok 12.0.1
timer.h
Go to the documentation of this file.
1// Copyright 2023 Google LLC
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#ifndef HIGHWAY_HWY_TIMER_H_
17#define HIGHWAY_HWY_TIMER_H_
18
19// Platform-specific timer functions. Provides Now() and functions for
20// interpreting and converting the timer-inl.h Ticks.
21
22#include <stdint.h>
23
24#include "hwy/highway_export.h"
25
26namespace hwy {
27namespace platform {
28
29// Returns current timestamp [in seconds] relative to an unspecified origin.
30// Features: monotonic (no negative elapsed time), steady (unaffected by system
31// time changes), high-resolution (on the order of microseconds).
32// Uses InvariantTicksPerSecond and the baseline version of timer::Start().
34
35// Functions for use with timer-inl.h:
36
37// Returns whether it is safe to call timer::Stop without executing an illegal
38// instruction; if false, fills cpu100 (a pointer to a 100 character buffer)
39// with the CPU brand string or an empty string if unknown.
40HWY_DLLEXPORT bool HaveTimerStop(char* cpu100);
41
42// Returns tick rate, useful for converting timer::Ticks to seconds. Invariant
43// means the tick counter frequency is independent of CPU throttling or sleep.
44// This call may be expensive, callers should cache the result.
46
47// Returns ticks elapsed in back to back timer calls, i.e. a function of the
48// timer resolution (minimum measurable difference) and overhead.
49// This call is expensive, callers should cache the result.
51
52} // namespace platform
53
54struct Timestamp {
56 double t;
57};
58
59static inline double SecondsSince(const Timestamp& t0) {
60 const Timestamp t1;
61 return t1.t - t0.t;
62}
63
64} // namespace hwy
65
66#endif // HIGHWAY_HWY_TIMER_H_
#define HWY_DLLEXPORT
Definition highway_export.h:13
HWY_DLLEXPORT bool HaveTimerStop(char *cpu100)
HWY_DLLEXPORT uint64_t TimerResolution()
HWY_DLLEXPORT double Now()
HWY_DLLEXPORT double InvariantTicksPerSecond()
Definition abort.h:8
static double SecondsSince(const Timestamp &t0)
Definition timer.h:59
Definition timer.h:54
double t
Definition timer.h:56
Timestamp()
Definition timer.h:55