RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
Cr2sRawInterpolatorBenchmark.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2017 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/Array2DRef.h"
23#include "adt/Casts.h"
24#include "adt/Point.h"
25#include "bench/Common.h"
26#include "common/Common.h"
27#include "common/RawImage.h"
28#include <array>
29#include <cstdint>
30#include <type_traits>
31#include <benchmark/benchmark.h>
32
38using std::array;
39using std::integral_constant;
40
41namespace {
42
43template <int N> using v = integral_constant<int, N>;
44
45template <const iPoint2D& subSampling, typename version>
46inline void BM_Cr2sRawInterpolator(benchmark::State& state) {
47 static const array<int, 3> sraw_coeffs = {{999, 1000, 1001}};
48 static const int hue = 1269;
49
50 iPoint2D interpolatedDims = areaToRectangle(state.range(0), {3, 2});
51
52 interpolatedDims.x =
53 rawspeed::implicit_cast<int>(roundUp(interpolatedDims.x, 6));
54 if constexpr (subSampling.y == 2)
55 interpolatedDims.x =
56 rawspeed::implicit_cast<int>(roundUp(interpolatedDims.x, 4));
57
58 iPoint2D subsampledDim = interpolatedDims;
59 subsampledDim.x /= subSampling.x;
60 subsampledDim.y /= subSampling.y;
61 subsampledDim.x *= 2 + subSampling.x * subSampling.y;
62
63 RawImage subsampledRaw =
64 RawImage::create(subsampledDim, RawImageType::UINT16, 1);
65 subsampledRaw->metadata.subsampling = subSampling;
66
67 RawImage mRaw = RawImage::create(interpolatedDims, RawImageType::UINT16, 3);
68 mRaw->metadata.subsampling = subSampling;
69
71 sraw_coeffs, hue);
72
73 for (auto _ : state)
74 i.interpolate(version::value);
75
76 state.SetComplexityN(interpolatedDims.area());
77 state.counters.insert(
78 {{"Pixels", benchmark::Counter(
79 state.complexity_length_n(),
80 benchmark::Counter::Flags::kIsIterationInvariantRate)},
81 {"Bytes",
82 benchmark::Counter(3UL * sizeof(uint16_t) * state.complexity_length_n(),
83 benchmark::Counter::Flags::kIsIterationInvariantRate,
84 benchmark::Counter::kIs1024)}});
85}
86
87inline void CustomArguments(benchmark::internal::Benchmark* b) {
88 b->MeasureProcessCPUTime();
89 b->UseRealTime();
90
91 if (benchmarkDryRun()) {
92 static constexpr int L2dByteSize = 512U * (1U << 10U);
93 b->Arg((L2dByteSize / (16 / 8)) / (3 * 2));
94 return;
95 }
96
97 b->RangeMultiplier(2);
98 if constexpr ((true)) {
99 b->Arg(2 * 3 * 2 * 1'000'000);
100 } else {
101 b->Range(1, 256 << 20)->Complexity(benchmark::oN);
102 }
103 b->Unit(benchmark::kMillisecond);
104}
105
106constexpr const iPoint2D S422(2, 1);
110
111constexpr const iPoint2D S420(2, 2);
114
115} // namespace
116
constexpr uint64_t RAWSPEED_READNONE roundUp(uint64_t value, uint64_t multiple)
Definition Common.h:134
BENCHMARK_MAIN()
constexpr uint64_t RAWSPEED_READNONE roundUp(uint64_t value, uint64_t multiple)
Definition Common.h:134
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
Array2DRef< uint16_t > getU16DataAsUncroppedArray2DRef() noexcept
Definition RawImage.h:290
ImageMetaData metadata
Definition RawImage.h:184
value_type x
Definition Point.h:102
value_type y
Definition Point.h:103
area_type RAWSPEED_READONLY area() const
Definition Point.h:81
BENCHMARK_TEMPLATE(BM_Cr2sRawInterpolator, S422, v< 0 >) -> Apply(CustomArguments)
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