RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
UncompressedDecompressorBenchmark.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
22#include "adt/Casts.h"
23#include "adt/Point.h"
24#include "bench/Common.h"
26#include "common/Common.h"
27#include "common/RawImage.h"
28#include "io/Buffer.h"
29#include "io/ByteStream.h"
30#include "io/Endianness.h"
31#include <cassert>
32#include <cstddef>
33#include <cstdint>
34#include <numeric>
35#include <type_traits>
36#include <vector>
37#include <benchmark/benchmark.h>
38
42
43namespace {
44
45template <size_t N> using BPS = std::integral_constant<size_t, N>;
46
47template <typename T, BitOrder BO, typename BPS>
48inline void BM_UncompressedDecompressor(benchmark::State& state) {
49 static_assert(BPS::value > 0, "bad bps");
50
51 auto dim = areaToRectangle(state.range(0));
52
53 int inputPitchBits = BPS::value * dim.x;
54 inputPitchBits = rawspeed::implicit_cast<int>(
55 rawspeed::roundUp(inputPitchBits, std::lcm(8, BPS::value)));
56 assert(inputPitchBits % 8 == 0);
57 int inputPitchBytes = inputPitchBits / 8;
58 assert(inputPitchBits % BPS::value == 0);
59 dim.x = inputPitchBits / BPS::value;
60
61 auto packedLength = rawspeed::implicit_cast<int>(
62 rawspeed::roundUp(inputPitchBytes * dim.y, 4));
63 const std::vector<uint8_t> buf(packedLength);
65 Buffer(buf.data(), packedLength), rawspeed::Endianness::little));
66
68 std::is_same_v<T, float>
71 1);
72
73 for (auto _ : state) {
74 UncompressedDecompressor d(bs, mRaw,
75 rawspeed::iRectangle2D({0, 0}, mRaw->dim),
76 inputPitchBytes, BPS::value, BO);
78 }
79
80 state.SetComplexityN(dim.area());
81 state.SetItemsProcessed(state.complexity_length_n() * state.iterations());
82 state.SetBytesProcessed(BPS::value * state.items_processed() / 8);
83}
84
85inline void CustomArgs(benchmark::internal::Benchmark* b) {
86 b->Unit(benchmark::kMicrosecond);
87
88 if (benchmarkDryRun()) {
89 static constexpr int L2dByteSize = 512U * (1U << 10U);
90 b->Arg((L2dByteSize / (32 / 8)) / 2);
91 return;
92 }
93
94 b->RangeMultiplier(2);
95 b->Range(1, 1 * 1024 * 1024)->Complexity(benchmark::oN);
96}
97
98#define GEN_INNER(a, b, c) \
99 BENCHMARK_TEMPLATE(BM_UncompressedDecompressor, a, b, BPS<c>) \
100 ->Apply(CustomArgs);
101
102#define GEN_F_BPS(b, c) GEN_INNER(float, b, c)
103
104#define GEN_F(b) \
105 GEN_F_BPS(b, 16) \
106 GEN_F_BPS(b, 24) \
107 GEN_F_BPS(b, 32)
108
109#define GEN_U_BPS(b, c) GEN_INNER(uint16_t, b, c)
110
111#define GEN_U(b) \
112 GEN_U_BPS(b, 1) \
113 GEN_U_BPS(b, 2) \
114 GEN_U_BPS(b, 3) \
115 GEN_U_BPS(b, 4) \
116 GEN_U_BPS(b, 5) \
117 GEN_U_BPS(b, 6) \
118 GEN_U_BPS(b, 7) \
119 GEN_U_BPS(b, 8) \
120 GEN_U_BPS(b, 9) \
121 GEN_U_BPS(b, 10) \
122 GEN_U_BPS(b, 11) \
123 GEN_U_BPS(b, 12) \
124 GEN_U_BPS(b, 13) \
125 GEN_U_BPS(b, 14) \
126 GEN_U_BPS(b, 15) \
127 GEN_U_BPS(b, 16)
128
129#define GEN_BO(b) GEN_U(b) GEN_F(b)
130
131GEN_BO(BitOrder::LSB)
132GEN_BO(BitOrder::MSB)
133GEN_U(BitOrder::MSB16)
134GEN_U(BitOrder::MSB32)
135
136} // namespace
137
BENCHMARK_MAIN()
iPoint2D dim(rawspeed::implicit_cast< int >(ceil(sqSide *sqARatio)), rawspeed::implicit_cast< int >(ceil(sqSide/sqARatio)))
Definition Common.cpp:55
assert(dim.area() >=area)
bool RAWSPEED_READNONE benchmarkDryRun()
rawspeed::iPoint2D RAWSPEED_READNONE areaToRectangle(uint64_t area, rawspeed::iPoint2D aspect={2, 2})
static RawImage create(RawImageType type=RawImageType::UINT16)
Definition RawImage.h:265
constexpr uint64_t RAWSPEED_READNONE roundUp(uint64_t value, uint64_t multiple)
Definition Common.h:134
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32