RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
CommonBenchmark.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2023 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "bench/Common.h"
22#include "adt/Point.h"
23#include "common/Common.h"
24#include <cstddef>
25#include <cstdint>
26#include <vector>
27#include <benchmark/benchmark.h>
28
31
32namespace {
33
34void BM_CopyPixels(benchmark::State& state, bool padddedRows) {
35 iPoint2D dims = areaToRectangle(state.range(0), {3, 2});
36
37 const int width = dims.x;
38 const int height = dims.y;
39
40 int dstPitch = dims.x;
41 int srcPitch = dims.x;
42
43 if (padddedRows) {
44 dstPitch *= 2;
45 srcPitch *= 2;
46 }
47
48 std::vector<uint8_t> dst(static_cast<size_t>(dstPitch) * height, uint8_t(0));
49 std::vector<uint8_t> src(static_cast<size_t>(srcPitch) * height, uint8_t(0));
50
51 for (auto _ : state) {
52 copyPixels(reinterpret_cast<std::byte*>(&(dst[0])), dstPitch,
53 reinterpret_cast<const std::byte*>(&(src[0])), srcPitch, width,
54 height);
55 }
56
57 state.SetComplexityN(dims.area());
58 state.counters.insert(
59 {{"Bytes",
60 benchmark::Counter(sizeof(uint8_t) * dims.area(),
61 benchmark::Counter::Flags::kIsIterationInvariantRate,
62 benchmark::Counter::kIs1024)}});
63}
64
65void BM_CopyPixels2DContiguous(benchmark::State& state) {
66 BM_CopyPixels(state, /*padddedRows=*/false);
67}
68
69void BM_CopyPixels2DStrided(benchmark::State& state) {
70 BM_CopyPixels(state, /*padddedRows=*/true);
71}
72
73inline void CustomArguments(benchmark::internal::Benchmark* b) {
74 b->MeasureProcessCPUTime();
75 b->UseRealTime();
76 b->Unit(benchmark::kMicrosecond);
77
78 static constexpr int L2dByteSize = 512U * (1U << 10U);
79 static constexpr int L2dNPixels = L2dByteSize / 2;
80 static constexpr int MaxPixelsOptimal = (1 << 5) * L2dNPixels;
81
82 if (benchmarkDryRun()) {
83 b->Arg(L2dNPixels);
84 return;
85 }
86
87 b->RangeMultiplier(2);
88 if constexpr ((false)) {
89 b->Arg(MaxPixelsOptimal);
90 } else {
91 b->Range(1, 2 * MaxPixelsOptimal)->Complexity(benchmark::oN);
92 }
93}
94
97
98} // namespace
99
void copyPixels(std::byte *destPtr, int dstPitch, const std::byte *srcPtr, int srcPitch, int rowSize, int height)
Definition Common.h:79
BENCHMARK_MAIN()
bool RAWSPEED_READNONE benchmarkDryRun()
rawspeed::iPoint2D RAWSPEED_READNONE areaToRectangle(uint64_t area, rawspeed::iPoint2D aspect={2, 2})
value_type x
Definition Point.h:102
value_type y
Definition Point.h:103
area_type RAWSPEED_READONLY area() const
Definition Point.h:81
void BM_CopyPixels2DStrided(benchmark::State &state)
void BM_CopyPixels2DContiguous(benchmark::State &state)
BENCHMARK(BM_CopyPixels2DContiguous) -> Apply(CustomArguments)
void BM_CopyPixels(benchmark::State &state, bool padddedRows)
void CustomArguments(benchmark::internal::Benchmark *b)
void copyPixels(std::byte *destPtr, int dstPitch, const std::byte *srcPtr, int srcPitch, int rowSize, int height)
Definition Common.h:79