tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
cycle_counter_x86.h
Go to the documentation of this file.
1#pragma once
2
3#include <x86intrin.h>
4
10namespace detail
11{
12
21 {
22 unsigned long long start_cycles;
23 unsigned long long total_cycles = 0;
24 unsigned long long runs = 0;
25
27 FORCE_INLINE void start() noexcept
28 {
29 _mm_lfence();
30 start_cycles = __rdtsc();
31 }
32
34 FORCE_INLINE void stop() noexcept
35 {
36 unsigned long long end = __rdtsc();
37 _mm_lfence();
38 total_cycles += (end - start_cycles);
39 ++runs;
40 }
41
43 void reset() noexcept
44 {
45 total_cycles = 0;
46 runs = 0;
47 }
48
50 double avg_cycles() const { return static_cast<double>(total_cycles) / runs; }
51 };
52
53} // namespace detail
#define FORCE_INLINE
Hint the compiler to always inline a function.
Definition config.h:26
Definition BaseExpr.h:4
Hardware cycle counter for x86/x86_64.
Definition cycle_counter_x86.h:21
void reset() noexcept
Reset accumulated cycles and run count to zero.
Definition cycle_counter_x86.h:43
unsigned long long start_cycles
Definition cycle_counter_x86.h:22
unsigned long long total_cycles
Definition cycle_counter_x86.h:23
FORCE_INLINE void stop() noexcept
Record the ending cycle count and accumulate.
Definition cycle_counter_x86.h:34
unsigned long long runs
Definition cycle_counter_x86.h:24
double avg_cycles() const
Return the average cycles per start/stop pair.
Definition cycle_counter_x86.h:50
FORCE_INLINE void start() noexcept
Record the starting cycle count (serialized).
Definition cycle_counter_x86.h:27