Project
Loading...
Searching...
No Matches
bench_ransCombinedIterator.cxx
Go to the documentation of this file.
1// Copyright 2019-2023 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
15
16#include <vector>
17
18#include <benchmark/benchmark.h>
19
20#include "rANS/iterator.h"
21
22using namespace o2::rans;
23
24static void BM_Array_Read_Copy(benchmark::State& state)
25{
26 std::vector<uint32_t> a(state.range(0), 0x0);
27 std::vector<uint32_t> b(state.range(0), 0x1);
28 std::vector<uint32_t> c(state.range(0), 0x0);
29 for (auto _ : state) {
30 std::vector<uint32_t> tmp(state.range(0));
31
32 for (size_t i = 0; i < a.size(); ++i) {
33 tmp[i] = b[i] + (a[i] << 16);
34 }
35
36 for (size_t i = 0; i < tmp.size(); ++i) {
37 c[i] = tmp[i] + 1;
38 }
39 }
40}
41
42BENCHMARK(BM_Array_Read_Copy)->RangeMultiplier(2)->Range(10e4, 2 * 10e6);
43
44static void BM_Array_Read_Iterator(benchmark::State& state)
45{
46 std::vector<uint32_t> a(state.range(0), 0x0);
47 std::vector<uint32_t> b(state.range(0), 0x1);
48 std::vector<uint32_t> c(state.range(0), 0x0);
49
50 for (auto _ : state) {
51 auto readOP = [](auto iterA, auto iterB) -> uint32_t {
52 return *iterB + (*iterA << 16);
53 };
54
55 const CombinedInputIterator begin(a.begin(), b.begin(), readOP);
56 const CombinedInputIterator end(a.end(), b.end(), readOP);
57
58 auto cIter = c.begin();
59
60 for (auto iter = begin; iter != end; ++iter) {
61 *cIter = *iter + 1;
62 ++cIter;
63 }
64 }
65}
66
67BENCHMARK(BM_Array_Read_Iterator)->RangeMultiplier(2)->Range(10e4, 2 * 10e6);
68
69static void BM_Array_Write_Copy(benchmark::State& state)
70{
71 std::vector<uint32_t> a(state.range(0), 0x0);
72 std::vector<uint32_t> b(state.range(0), 0x0);
73 std::vector<uint32_t> c(state.range(0), 0x0001000f);
74 for (auto _ : state) {
75 std::vector<uint32_t> tmp(state.range(0));
76
77 for (size_t i = 0; i < c.size(); ++i) {
78 tmp[i] = c[i] + 1;
79 }
80
81 for (size_t i = 0; i < a.size(); ++i) {
82 const uint32_t shift = 16;
83 a[i] = tmp[i] >> shift;
84 b[i] = tmp[i] & ((1 << shift) - 1);
85 }
86 }
87}
88
89BENCHMARK(BM_Array_Write_Copy)->RangeMultiplier(2)->Range(10e4, 2 * 10e6);
90
91static void BM_Array_Write_Iterator(benchmark::State& state)
92{
93 std::vector<uint32_t> a(state.range(0), 0x0);
94 std::vector<uint32_t> b(state.range(0), 0x0);
95 std::vector<uint32_t> c(state.range(0), 0x0001000f);
96
97 for (auto _ : state) {
98 auto writeOP = [](auto iterA, auto iterB, uint32_t value) -> void {
99 const uint32_t shift = 16;
100 *iterA = value >> shift;
101 *iterB = value & ((1 << shift) - 1);
102 };
103
104 auto out = CombinedOutputIteratorFactory<uint32_t>::makeIter(a.begin(), b.begin(), writeOP);
105
106 for (auto iter = c.begin(); iter != c.end(); ++iter) {
107 *out = *iter + 1;
108 ++out;
109 }
110 }
111}
112
113BENCHMARK(BM_Array_Write_Iterator)->RangeMultiplier(2)->Range(10e4, 2 * 10e6);
114
benchmark::State & state
int32_t i
uint32_t c
Definition RawData.h:2
BENCHMARK_MAIN()
BENCHMARK(BM_Array_Read_Copy) -> RangeMultiplier(2) ->Range(10e4, 2 *10e6)
GLuint GLuint end
Definition glcorearb.h:469
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
public interface for rANS iterators.
static auto makeIter(iterA_T iterA, iterB_T iterB, F functor) -> CombinedOutputIterator< input_T, iterA_T, iterB_T, F >
Definition iterator.h:207