RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
BitStreamerJPEGBenchmark.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2024 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/Array1DRef.h"
23#include "adt/Invariant.h"
24#include "adt/Optional.h"
25#include "bench/Common.h"
28#include <cassert>
29#include <cstdint>
30#include <benchmark/benchmark.h>
31
32#ifndef NDEBUG
33#include <limits>
34#endif
35
36namespace rawspeed {
37
38namespace {
39
40template <typename T> void BM(benchmark::State& state, bool Stuffed) {
41 int64_t numBytes = state.range(0);
42 assert(numBytes > 0);
43 assert(numBytes <= std::numeric_limits<int>::max());
44
48 if (Stuffed) {
49 genStuffed.emplace(numBytes, /*AppendStuffingByte=*/true);
50 numBytes = genStuffed->numBytesGenerated;
51 input = genStuffed->getInput();
52 } else {
53 genUnstuffed.emplace(numBytes);
54 numBytes = genUnstuffed->numBytesGenerated;
55 input = genUnstuffed->getInput();
56 }
57 benchmark::DoNotOptimize(input->begin());
58
59 for (auto _ : state) {
60 T bs(*input);
61
62 constexpr int MaxGetBits = 32;
63 int processedBytes = 0;
64 for (processedBytes = 0; processedBytes != numBytes;
65 processedBytes += MaxGetBits / 8) {
66 uint32_t bits = bs.getBits(MaxGetBits);
67 benchmark::DoNotOptimize(bits);
68 }
69 invariant(numBytes == processedBytes);
70 }
71
72 state.SetComplexityN(numBytes);
73 state.counters.insert({
74 {"Throughput",
75 benchmark::Counter(sizeof(uint8_t) * state.complexity_length_n(),
76 benchmark::Counter::Flags::kIsIterationInvariantRate,
77 benchmark::Counter::kIs1024)},
78 {"Latency",
79 benchmark::Counter(sizeof(uint8_t) * state.complexity_length_n(),
80 benchmark::Counter::Flags::kIsIterationInvariantRate |
81 benchmark::Counter::Flags::kInvert,
82 benchmark::Counter::kIs1000)},
83 });
84}
85
86void CustomArguments(benchmark::internal::Benchmark* b) {
87 b->Unit(benchmark::kMicrosecond);
88 b->RangeMultiplier(2);
89
90 static constexpr int L1dByteSize = 32U * (1U << 10U);
91 static constexpr int L2dByteSize = 512U * (1U << 10U);
92 static constexpr int MaxBytesOptimal = L2dByteSize * (1U << 5);
93
94 if (benchmarkDryRun()) {
95 b->Arg(L1dByteSize);
96 return;
97 }
98
99 if constexpr ((true)) {
100 b->Arg(MaxBytesOptimal);
101 } else {
102 b->Range(8, MaxBytesOptimal * (1U << 2));
103 b->Complexity(benchmark::oN);
104 }
105}
106
107#ifndef BENCHMARK_TEMPLATE1_CAPTURE
108// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
109#define BENCHMARK_TEMPLATE1_CAPTURE(func, a, test_case_name, ...) \
110 BENCHMARK_PRIVATE_DECLARE(func) = \
111 (::benchmark::internal::RegisterBenchmarkInternal( \
112 new ::benchmark::internal::FunctionBenchmark( \
113 #func "<" #a ">" \
114 "/" #test_case_name, \
115 [](::benchmark::State& st) { func<a>(st, __VA_ARGS__); })))
116#endif // BENCHMARK_TEMPLATE1_CAPTURE
117
121 ->Apply(CustomArguments);
123 ->Apply(CustomArguments);
124
125} // namespace
126
127} // namespace rawspeed
128
#define BENCHMARK_TEMPLATE1_CAPTURE(func, a, test_case_name,...)
BENCHMARK_MAIN()
#define invariant(expr)
Definition Invariant.h:27
assert(dim.area() >=area)
bool RAWSPEED_READNONE benchmarkDryRun()
T & emplace(Args &&... args)
Definition Optional.h:51
throw T(buf.data())