grpc
third_party
protobuf
third_party
benchmark
test
protobuf/third_party/benchmark/test/donotoptimize_test.cc
Go to the documentation of this file.
1
#include "benchmark/benchmark.h"
2
3
#include <cstdint>
4
5
namespace
{
6
#if defined(__GNUC__)
7
std::uint64_t
double_up(
const
std::uint64_t
x
)
__attribute__
((
const
));
8
#endif
9
std::uint64_t
double_up(
const
std::uint64_t
x
) {
return
x
* 2; }
10
}
11
12
// Using DoNotOptimize on types like BitRef seem to cause a lot of problems
13
// with the inline assembly on both GCC and Clang.
14
struct
BitRef
{
15
int
index
;
16
unsigned
char
&
byte
;
17
18
public
:
19
static
BitRef
Make
() {
20
static
unsigned
char
arr[2] = {};
21
BitRef
b
(1, arr[0]);
22
return
b
;
23
}
24
private
:
25
BitRef
(
int
i
,
unsigned
char
&
b
) :
index
(
i
),
byte
(
b
) {}
26
};
27
28
int
main
(
int
,
char
*[]) {
29
// this test verifies compilation of DoNotOptimize() for some types
30
31
char
buffer8[8];
32
benchmark::DoNotOptimize
(buffer8);
33
34
char
buffer20[20];
35
benchmark::DoNotOptimize
(buffer20);
36
37
char
buffer1024[1024];
38
benchmark::DoNotOptimize
(buffer1024);
39
benchmark::DoNotOptimize
(&buffer1024[0]);
40
41
int
x
= 123;
42
benchmark::DoNotOptimize
(
x
);
43
benchmark::DoNotOptimize
(&
x
);
44
benchmark::DoNotOptimize
(
x
+= 42);
45
46
benchmark::DoNotOptimize
(double_up(
x
));
47
48
// These tests are to e
49
benchmark::DoNotOptimize
(
BitRef::Make
());
50
BitRef
lval =
BitRef::Make
();
51
benchmark::DoNotOptimize
(lval);
52
}
benchmark::DoNotOptimize
BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const &value)
Definition:
benchmark/include/benchmark/benchmark.h:375
BitRef::byte
unsigned char & byte
Definition:
benchmark/test/donotoptimize_test.cc:16
BitRef::BitRef
BitRef(int i, unsigned char &b)
Definition:
protobuf/third_party/benchmark/test/donotoptimize_test.cc:25
BitRef
Definition:
benchmark/test/donotoptimize_test.cc:14
uint64_t
unsigned __int64 uint64_t
Definition:
stdint-msvc2008.h:90
__attribute__
__attribute__(void) start
x
int x
Definition:
bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
b
uint64_t b
Definition:
abseil-cpp/absl/container/internal/layout_test.cc:53
BitRef::Make
static BitRef Make()
Definition:
protobuf/third_party/benchmark/test/donotoptimize_test.cc:19
BitRef::index
int index
Definition:
benchmark/test/donotoptimize_test.cc:15
main
int main(int, char *[])
Definition:
protobuf/third_party/benchmark/test/donotoptimize_test.cc:28
i
uint64_t i
Definition:
abseil-cpp/absl/container/btree_benchmark.cc:230
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:17