ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Columnar
ColumnarTestFixtures
ColumnarTestFixtures
Benchmark.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
#ifndef COLUMNAR_TEST_FIXTURES_BENCHMARK_H
9
#define COLUMNAR_TEST_FIXTURES_BENCHMARK_H
10
11
#include <optional>
12
#include <chrono>
13
#include <cstdint>
14
#include <iostream>
15
#include <string>
16
17
namespace
columnar
18
{
19
namespace
TestUtils
20
{
49
50
class
Benchmark
final
51
{
54
public
:
55
56
Benchmark
(
const
std::string& val_name =
""
,
unsigned
val_batchSize = 1)
57
:
m_name
(val_name),
m_batchSize
(val_batchSize)
58
{
59
if
(
m_name
.empty())
60
m_silence
=
true
;
61
}
62
63
~Benchmark
()
64
{
65
if
(
m_count
> 0 && !
m_silence
)
66
std::cout <<
m_name
<<
": "
<< std::chrono::duration<std::uint64_t,std::nano> (
m_ticks
) / (
m_count
*
m_batchSize
) << std::endl;
67
}
68
69
void
setSilence
()
70
{
71
m_silence
=
true
;
72
}
73
74
std::optional<float>
getEntryTime
(
float
emptyTime)
const
75
{
76
if
(
m_count
== 0)
77
return
std::nullopt;
78
return
static_cast<
float
>
((std::chrono::duration<float,std::nano> (
m_ticks
) / (
m_count
*
m_batchSize
)) / std::chrono::duration<float,std::nano> (1))-emptyTime/
m_batchSize
;
79
}
80
81
auto
getTotalTime
()
const
82
{
83
return
m_ticks
;
84
}
85
86
static
float
getTickDuration
()
87
{
88
using
period = std::chrono::high_resolution_clock::period;
89
return
static_cast<
float
>
(period::num) / period::den * 1e9f;
90
}
91
92
void
startTimer
()
93
{
94
m_start
= std::chrono::high_resolution_clock::now();
95
}
96
97
void
stopTimer
()
98
{
99
m_ticks
+= std::chrono::high_resolution_clock::now() -
m_start
;
100
m_count
+= 1;
101
}
102
103
104
107
private
:
108
109
std::string
m_name
;
110
111
std::chrono::time_point<std::chrono::high_resolution_clock>
m_start
;
112
114
std::chrono::high_resolution_clock::duration
m_ticks
{};
115
117
std::uint64_t
m_count
= 0;
118
120
unsigned
m_batchSize
= 1;
121
123
bool
m_silence
=
false
;
124
};
125
}
126
}
127
128
#endif
columnar::TestUtils::Benchmark::getTotalTime
auto getTotalTime() const
Definition
Benchmark.h:81
columnar::TestUtils::Benchmark::setSilence
void setSilence()
Definition
Benchmark.h:69
columnar::TestUtils::Benchmark::m_start
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
Definition
Benchmark.h:111
columnar::TestUtils::Benchmark::m_count
std::uint64_t m_count
the number of times the timer has been started
Definition
Benchmark.h:117
columnar::TestUtils::Benchmark::m_ticks
std::chrono::high_resolution_clock::duration m_ticks
accumulated time m_ticks
Definition
Benchmark.h:114
columnar::TestUtils::Benchmark::stopTimer
void stopTimer()
Definition
Benchmark.h:97
columnar::TestUtils::Benchmark::getTickDuration
static float getTickDuration()
Definition
Benchmark.h:86
columnar::TestUtils::Benchmark::m_batchSize
unsigned m_batchSize
the number of calls per batch
Definition
Benchmark.h:120
columnar::TestUtils::Benchmark::getEntryTime
std::optional< float > getEntryTime(float emptyTime) const
Definition
Benchmark.h:74
columnar::TestUtils::Benchmark::Benchmark
Benchmark(const std::string &val_name="", unsigned val_batchSize=1)
Definition
Benchmark.h:56
columnar::TestUtils::Benchmark::m_name
std::string m_name
Definition
Benchmark.h:109
columnar::TestUtils::Benchmark::startTimer
void startTimer()
Definition
Benchmark.h:92
columnar::TestUtils::Benchmark::~Benchmark
~Benchmark()
Definition
Benchmark.h:63
columnar::TestUtils::Benchmark::m_silence
bool m_silence
whether to suppress output
Definition
Benchmark.h:123
TestUtils
Definition
TestUtils.py:1
columnar
Definition
ClusterDef.h:16
Generated on
for ATLAS Offline Software by
1.17.0