benchmark
1.10.0
Toggle main menu visibility
Loading...
Searching...
No Matches
counter.h
1
// Copyright 2015 Google Inc. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef BENCHMARK_COUNTER_H_
16
#define BENCHMARK_COUNTER_H_
17
18
#if defined(_MSC_VER)
19
#pragma warning(push)
20
#pragma warning(disable : 4251)
21
#endif
22
23
#include <map>
24
#include <string>
25
26
#include "benchmark/macros.h"
27
#include "benchmark/types.h"
28
29
namespace
benchmark {
30
31
class
BENCHMARK_EXPORT Counter {
32
public
:
33
enum
Flags {
34
kDefaults = 0,
35
kIsRate = 1 << 0,
36
kAvgThreads = 1 << 1,
37
kAvgThreadsRate = kIsRate | kAvgThreads,
38
kIsIterationInvariant = 1 << 2,
39
kIsIterationInvariantRate = kIsRate | kIsIterationInvariant,
40
kAvgIterations = 1 << 3,
41
kAvgIterationsRate = kIsRate | kAvgIterations,
42
kStringifyExponent = 1 << 4,
43
kInvert = 1 << 31
44
};
45
46
enum
OneK { kIs1000 = 1000, kIs1024 = 1024 };
47
48
double
value;
49
Flags flags;
50
OneK oneK;
51
52
BENCHMARK_ALWAYS_INLINE
53
Counter(
double
v = 0., Flags f = kDefaults, OneK k = kIs1000)
54
: value(v), flags(f), oneK(k) {}
55
56
BENCHMARK_ALWAYS_INLINE
operator
double
const
&()
const
{
return
value; }
57
BENCHMARK_ALWAYS_INLINE
operator
double
&() {
return
value; }
58
};
59
60
Counter::Flags
inline
operator|(
const
Counter::Flags& LHS,
61
const
Counter::Flags& RHS) {
62
return
static_cast<
Counter::Flags
>
(
static_cast<
int
>
(LHS) |
63
static_cast<
int
>
(RHS));
64
}
65
66
using
UserCounters = std::map<std::string, Counter>;
67
68
namespace
internal {
69
void
Finish(UserCounters* l, IterationCount iterations,
double
cpu_time,
70
double
num_threads);
71
void
Increment(UserCounters* l, UserCounters
const
& r);
72
bool
SameNames(UserCounters
const
& l, UserCounters
const
& r);
73
}
// namespace internal
74
75
}
// namespace benchmark
76
77
#if defined(_MSC_VER)
78
#pragma warning(pop)
79
#endif
80
81
#endif
// BENCHMARK_COUNTER_H_
include
benchmark
counter.h
Generated by
1.18.0