RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
DefaultInitAllocatorAdaptorBenchmark.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2018 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 "bench/Common.h"
24#include <cstddef>
25#include <memory>
26#include <vector>
27#include <benchmark/benchmark.h>
28
29using Type = std::byte;
30
31namespace {
32
33template <typename Allocator> void construct(benchmark::State& state) {
34 std::vector<Type, Allocator> vec(
35 rawspeed::implicit_cast<size_t>(state.range(0)));
36 benchmark::DoNotOptimize(vec);
37}
38
39template <typename Allocator>
40void construct_with_zeroinit(benchmark::State& state) {
41 std::vector<Type, Allocator> vec(
42 rawspeed::implicit_cast<size_t>(state.range(0)), Type(0));
43 benchmark::DoNotOptimize(vec);
44}
45
46template <typename Worker>
47void BM_std_vector(benchmark::State& state, Worker worker) {
48 // Do it once outside of the loop to maybe offset the initial alloc time.
49 worker(state);
50
51 for (auto _ : state)
52 worker(state);
53
54 const auto AllocSize = sizeof(Type) * state.range(0);
55 state.counters["Allocation,bytes"] = benchmark::Counter(
56 rawspeed::implicit_cast<double>(AllocSize), benchmark::Counter::kDefaults,
57 benchmark::Counter::kIs1024);
58 state.SetComplexityN(AllocSize);
59 state.SetBytesProcessed(AllocSize * state.iterations());
60 state.SetItemsProcessed(state.range(0) * state.iterations());
61}
62
63void CustomArguments(benchmark::internal::Benchmark* b) {
64 if (benchmarkDryRun()) {
65 b->Arg(512U * (1U << 10U)); // 512 KiB
66 return;
67 }
68
69 b->RangeMultiplier(2)
70 ->Range(1U << 0U, 1U << 31U)
71 ->Complexity(benchmark::BigO::oN);
72}
73
74#define BENCHMARK_CAPTURE_NAME(func, ...) \
75 BENCHMARK_CAPTURE(func, #__VA_ARGS__, __VA_ARGS__)
76
82 rawspeed::DefaultInitAllocatorAdaptor<Type, std::allocator<Type>>>)
83 ->Apply(CustomArguments);
84
86 construct_with_zeroinit<std::allocator<Type>>)
87 ->Apply(CustomArguments);
91 rawspeed::DefaultInitAllocatorAdaptor<Type, std::allocator<Type>>>)
92 ->Apply(CustomArguments);
93
94} // namespace
95
#define BENCHMARK_CAPTURE_NAME(func,...)
BENCHMARK_MAIN()
bool RAWSPEED_READNONE benchmarkDryRun()
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32