RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
MD5Benchmark.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
21#include "md5.h"
22#include "adt/Casts.h"
23#include "bench/Common.h"
24#include <cstdint>
25#include <cstdlib>
26#include <vector>
27#include <benchmark/benchmark.h>
28
29namespace {
30
31void BM_MD5(benchmark::State& state) {
32 // Create a zero-initialized data. Content does not matter for our purpose.
33 std::vector<uint8_t> buf(rawspeed::implicit_cast<size_t>(state.range(0)),
34 uint8_t(0));
35
36 for (auto _ : state) {
37 auto hash = rawspeed::md5::md5_hash(buf.data(), buf.size());
38 benchmark::DoNotOptimize(hash);
39 }
40
41 state.SetComplexityN(buf.size());
42 state.counters.insert({
43 {"Throughput",
44 benchmark::Counter(sizeof(uint8_t) * state.complexity_length_n(),
45 benchmark::Counter::Flags::kIsIterationInvariantRate,
46 benchmark::Counter::kIs1024)},
47 {"Latency",
48 benchmark::Counter(sizeof(uint8_t) * state.complexity_length_n(),
49 benchmark::Counter::Flags::kIsIterationInvariantRate |
50 benchmark::Counter::Flags::kInvert,
51 benchmark::Counter::kIs1024)},
52 });
53}
54
55void CustomArguments(benchmark::internal::Benchmark* b) {
56 b->Unit(benchmark::kMillisecond);
57
58 static constexpr int L2dByteSize = 512U * (1U << 10U);
59 static constexpr int MaxBytesOptimal = 25 * 1000 * 1000 * sizeof(uint16_t);
60
61 if (benchmarkDryRun()) {
62 b->Arg(L2dByteSize);
63 return;
64 }
65
66 b->RangeMultiplier(2);
67 if constexpr ((true))
68 b->Arg(MaxBytesOptimal);
69 else
70 b->Range(1, 2048UL << 20)->Complexity(benchmark::oN);
71}
72
73} // namespace
74
76
BENCHMARK(BM_MD5) -> Apply(CustomArguments)
BENCHMARK_MAIN()
bool RAWSPEED_READNONE benchmarkDryRun()
void BM_MD5(benchmark::State &state)
void CustomArguments(benchmark::internal::Benchmark *b)
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32