Grok
12.0.1
src
lib
core
highway
hwy
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
26
namespace
hwy
{
27
namespace
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().
33
HWY_DLLEXPORT
double
Now
();
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.
40
HWY_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.
45
HWY_DLLEXPORT
double
InvariantTicksPerSecond
();
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.
50
HWY_DLLEXPORT
uint64_t
TimerResolution
();
51
52
}
// namespace platform
53
54
struct
Timestamp
{
55
Timestamp
() {
t
=
platform::Now
(); }
56
double
t
;
57
};
58
59
static
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_
highway_export.h
HWY_DLLEXPORT
#define HWY_DLLEXPORT
Definition
highway_export.h:13
hwy::platform::HaveTimerStop
HWY_DLLEXPORT bool HaveTimerStop(char *cpu100)
hwy::platform::TimerResolution
HWY_DLLEXPORT uint64_t TimerResolution()
hwy::platform::Now
HWY_DLLEXPORT double Now()
hwy::platform::InvariantTicksPerSecond
HWY_DLLEXPORT double InvariantTicksPerSecond()
hwy
Definition
abort.h:8
hwy::SecondsSince
static double SecondsSince(const Timestamp &t0)
Definition
timer.h:59
hwy::Timestamp
Definition
timer.h:54
hwy::Timestamp::t
double t
Definition
timer.h:56
hwy::Timestamp::Timestamp
Timestamp()
Definition
timer.h:55
Generated by
1.10.0