]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - utils/google-benchmark/test/donotoptimize_test.cc
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / utils / google-benchmark / test / donotoptimize_test.cc
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 int main(int, char*[]) {
13   // this test verifies compilation of DoNotOptimize() for some types
14
15   char buffer8[8];
16   benchmark::DoNotOptimize(buffer8);
17
18   char buffer20[20];
19   benchmark::DoNotOptimize(buffer20);
20
21   char buffer1024[1024];
22   benchmark::DoNotOptimize(buffer1024);
23   benchmark::DoNotOptimize(&buffer1024[0]);
24
25   int x = 123;
26   benchmark::DoNotOptimize(x);
27   benchmark::DoNotOptimize(&x);
28   benchmark::DoNotOptimize(x += 42);
29
30   benchmark::DoNotOptimize(double_up(x));
31
32   return 0;
33 }