Skip to content

Commit 4a675ca

Browse files
authored
Add internal benchmark (#99)
1 parent 01f78cf commit 4a675ca

File tree

3 files changed

+56
-42
lines changed

3 files changed

+56
-42
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ set(EXAMPLES
144144
examples/4-RateDerivedMetric.cxx
145145
examples/5-Benchmark.cxx
146146
examples/6-Increment.cxx
147-
examples/7-Latency.cxx
147+
examples/7-InternalBenchamrk.cxx
148148
examples/8-Multiple.cxx
149149
examples/9-AutoUpdate.cxx
150150
examples/10-Buffering.cxx

examples/7-InternalBenchamrk.cxx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
///
2+
/// \file 7-InternalBenchmark.cxx
3+
/// \author Adam Wegrzynek <[email protected]>
4+
///
5+
6+
#include "Monitoring/MonitoringFactory.h"
7+
#include <iomanip>
8+
9+
using namespace o2::monitoring;
10+
using namespace std::chrono;
11+
12+
void test(std::unique_ptr<Monitoring>& monitoring) {
13+
for (int i = 0; i < 100000; i++) {
14+
monitoring->send({10, "myMetricInt"});
15+
monitoring->send({10.10, "myMetricFloat"});
16+
}
17+
}
18+
19+
void testWithTags(std::unique_ptr<Monitoring>& monitoring) {
20+
monitoring->addGlobalTag("benchmark", "yes");
21+
for (int i = 0; i < 100000; i++) {
22+
monitoring->send(Metric{10, "myMetricInt"}.addTags({{"tag1", "val1"}}));
23+
monitoring->send(Metric{10.10, "myMetricFloat"}.addTags({{"tag2", "val2"}}));
24+
}
25+
}
26+
27+
int main(int argc, char** argv) {
28+
static constexpr std::array<std::string_view,4> backends = {
29+
"no-op://",
30+
"flume://localhost:1234",
31+
"influxdb-udp://localhost:1234",
32+
"stdout://"
33+
};
34+
std::cout << "| " << std::setw(30) << "Backend" << " |"
35+
<< std::setw(10) << "no tags" << " |"
36+
<< std::setw(10) << " (2+1) tags" << " |" << std::endl;
37+
std::cout << "+--------------------------------+-------------+-------------+" << std::endl;
38+
for(auto& backend : backends) {
39+
std::cout.setstate(std::ios_base::failbit);
40+
auto monitoring = MonitoringFactory::Get(std::string(backend));
41+
42+
high_resolution_clock::time_point t1 = high_resolution_clock::now();
43+
test(monitoring);
44+
high_resolution_clock::time_point t2 = high_resolution_clock::now();
45+
46+
high_resolution_clock::time_point t3 = high_resolution_clock::now();
47+
testWithTags(monitoring);
48+
high_resolution_clock::time_point t4 = high_resolution_clock::now();
49+
50+
std::cout.clear();
51+
std::cout << "| " << std::setw(30) << backend << " |";
52+
std::cout << std::setw(10) << duration_cast<milliseconds>(t2 - t1).count() << "us |";
53+
std::cout << std::setw(10) << duration_cast<milliseconds>(t4 - t3).count() << "us |" << std::endl;
54+
}
55+
}

examples/7-Latency.cxx

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)