Skip to content

Commit 6eeacf1

Browse files
Adding benchmark for DPLRawPageOrganizer
With on average 4 sequences of variable length per page the binary and forward search give the following result. The parameter denotes the number of raw pages in one message. 16 messages are emulated with random sequence length. -------------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------------- BM_DPLRawPageSequencerBinary/64 2726 ns 2725 ns 316405 BM_DPLRawPageSequencerBinary/512 5313 ns 5313 ns 142040 BM_DPLRawPageSequencerBinary/1024 6564 ns 6564 ns 100000 BM_DPLRawPageSequencerForward/64 21699 ns 21699 ns 32390 BM_DPLRawPageSequencerForward/512 339023 ns 339022 ns 1945 BM_DPLRawPageSequencerForward/1024 1036609 ns 1036533 ns 580
1 parent 47571f0 commit 6eeacf1

2 files changed

Lines changed: 104 additions & 0 deletions

File tree

Framework/Utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ endforeach()
8888
if (TARGET benchmark::benchmark)
8989
foreach(b
9090
RawParser
91+
DPLRawPageSequencer
9192
)
9293
o2_add_test(benchmark_${b} NAME test_Framework_benchmark_${b}
9394
SOURCES test/benchmark_${b}.cxx
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// @file benchmark_DPLRawPageSequencer.h
13+
/// @author Matthias Richter
14+
/// @since 2021-07-21
15+
/// @brief Unit test for the DPL raw page sequencer utility
16+
17+
#include <benchmark/benchmark.h>
18+
19+
#include "DPLUtils/DPLRawPageSequencer.h"
20+
#include "RawPageTestData.h"
21+
#include <random>
22+
#include <vector>
23+
24+
using namespace o2::framework;
25+
auto const PAGESIZE = test::PAGESIZE;
26+
27+
auto createData(int nPages)
28+
{
29+
const int nParts = 16;
30+
std::vector<InputSpec> inputspecs = {
31+
InputSpec{"tpc", "TPC", "RAWDATA", 0, Lifetime::Timeframe}};
32+
33+
std::vector<DataHeader> dataheaders;
34+
dataheaders.emplace_back("RAWDATA", "TPC", 0, nPages * PAGESIZE, 0, nParts);
35+
36+
std::random_device rd;
37+
std::uniform_int_distribution<> lengthDist(1, nPages);
38+
auto randlength = [&rd, &lengthDist]() {
39+
return lengthDist(rd);
40+
};
41+
42+
int rdhCount = 0;
43+
// whenever a new id is created, it is done from the current counter
44+
// position, so we also have the possibility to calculate the length
45+
std::vector<uint16_t> fees;
46+
auto nextlength = randlength();
47+
auto createFEEID = [&rdhCount, &fees, &nPages, &randlength, &nextlength]() {
48+
if (rdhCount % nPages == 0 || rdhCount - fees.back() > nextlength) {
49+
fees.emplace_back(rdhCount);
50+
nextlength = randlength();
51+
}
52+
return fees.back();
53+
};
54+
auto amendRdh = [&rdhCount, createFEEID](test::RAWDataHeader& rdh) {
55+
rdh.feeId = createFEEID();
56+
rdhCount++;
57+
};
58+
59+
return test::createData(inputspecs, dataheaders, amendRdh);
60+
}
61+
62+
static void BM_DPLRawPageSequencerBinary(benchmark::State& state)
63+
{
64+
auto isSameRdh = [](const char* left, const char* right) -> bool {
65+
if (left == right) {
66+
return true;
67+
}
68+
69+
return reinterpret_cast<test::RAWDataHeader const*>(left)->feeId == reinterpret_cast<test::RAWDataHeader const*>(right)->feeId;
70+
};
71+
std::vector<std::pair<const char*, size_t>> pages;
72+
auto insertPages = [&pages](const char* ptr, size_t n) -> void {
73+
pages.emplace_back(ptr, n);
74+
};
75+
auto dataset = createData(state.range(0));
76+
for (auto _ : state) {
77+
DPLRawPageSequencer(dataset.record).binary(isSameRdh, insertPages);
78+
}
79+
}
80+
81+
static void BM_DPLRawPageSequencerForward(benchmark::State& state)
82+
{
83+
auto isSameRdh = [](const char* left, const char* right) -> bool {
84+
if (left == right) {
85+
return true;
86+
}
87+
88+
return reinterpret_cast<test::RAWDataHeader const*>(left)->feeId == reinterpret_cast<test::RAWDataHeader const*>(right)->feeId;
89+
};
90+
std::vector<std::pair<const char*, size_t>> pages;
91+
auto insertPages = [&pages](const char* ptr, size_t n) -> void {
92+
pages.emplace_back(ptr, n);
93+
};
94+
auto dataset = createData(state.range(0));
95+
for (auto _ : state) {
96+
DPLRawPageSequencer(dataset.record).forward(isSameRdh, insertPages);
97+
}
98+
}
99+
100+
BENCHMARK(BM_DPLRawPageSequencerBinary)->Arg(64)->Arg(512)->Arg(1024);
101+
BENCHMARK(BM_DPLRawPageSequencerForward)->Arg(64)->Arg(512)->Arg(1024);
102+
103+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)