Project
Loading...
Searching...
No Matches
benchmark_DPLRawPageSequencer.cxx
Go to the documentation of this file.
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
16
17#include <benchmark/benchmark.h>
18
20#include "RawPageTestData.h"
21#include <random>
22#include <vector>
23
24using namespace o2::framework;
25auto const PAGESIZE = test::PAGESIZE;
26
27auto 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
62static 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, uint32_t subSpec) -> 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
81static 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, uint32_t subSpec) -> 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
100BENCHMARK(BM_DPLRawPageSequencerBinary)->Arg(64)->Arg(512)->Arg(1024);
101BENCHMARK(BM_DPLRawPageSequencerForward)->Arg(64)->Arg(512)->Arg(1024);
102
benchmark::State & state
A parser and sequencer utility for raw pages within DPL input.
Raw page test data generator.
TBranch * ptr
auto const PAGESIZE
BENCHMARK(BM_DPLRawPageSequencerBinary) -> Arg(64) ->Arg(512) ->Arg(1024)
BENCHMARK_MAIN()
This utility handles transparently the DPL inputs and triggers a customizable action on sequences of ...
int binary(Predicate pred, Inserter inserter)
int forward(Predicate pred, Inserter inserter)
GLdouble n
Definition glcorearb.h:1982
GLdouble GLdouble right
Definition glcorearb.h:4077
GLint left
Definition glcorearb.h:1979
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
uint64_t feeId
bit 8 to 15: header size
DataSet createData()
std::random_device rd