abseil-cpp/absl/time/clock_benchmark.cc
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // https://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #include "absl/time/clock.h"
15 
16 #if !defined(_WIN32)
17 #include <sys/time.h>
18 #else
19 #include <winsock2.h>
20 #endif // _WIN32
21 #include <cstdio>
22 
23 #include "absl/base/internal/cycleclock.h"
24 #include "benchmark/benchmark.h"
25 
26 namespace {
27 
28 void BM_Clock_Now_AbslTime(benchmark::State& state) {
29  while (state.KeepRunning()) {
31  }
32 }
33 BENCHMARK(BM_Clock_Now_AbslTime);
34 
35 void BM_Clock_Now_GetCurrentTimeNanos(benchmark::State& state) {
36  while (state.KeepRunning()) {
38  }
39 }
40 BENCHMARK(BM_Clock_Now_GetCurrentTimeNanos);
41 
42 void BM_Clock_Now_AbslTime_ToUnixNanos(benchmark::State& state) {
43  while (state.KeepRunning()) {
45  }
46 }
47 BENCHMARK(BM_Clock_Now_AbslTime_ToUnixNanos);
48 
49 void BM_Clock_Now_CycleClock(benchmark::State& state) {
50  while (state.KeepRunning()) {
52  }
53 }
54 BENCHMARK(BM_Clock_Now_CycleClock);
55 
56 #if !defined(_WIN32)
57 static void BM_Clock_Now_gettimeofday(benchmark::State& state) {
58  struct timeval tv;
59  while (state.KeepRunning()) {
60  benchmark::DoNotOptimize(gettimeofday(&tv, nullptr));
61  }
62 }
63 BENCHMARK(BM_Clock_Now_gettimeofday);
64 
65 static void BM_Clock_Now_clock_gettime(benchmark::State& state) {
66  struct timespec ts;
67  while (state.KeepRunning()) {
68  benchmark::DoNotOptimize(clock_gettime(CLOCK_REALTIME, &ts));
69  }
70 }
71 BENCHMARK(BM_Clock_Now_clock_gettime);
72 #endif // _WIN32
73 
74 } // namespace
absl::ToUnixNanos
int64_t ToUnixNanos(Time t)
Definition: third_party/abseil-cpp/absl/time/time.cc:243
benchmark::DoNotOptimize
BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const &value)
Definition: benchmark/include/benchmark/benchmark.h:375
absl::GetCurrentTimeNanos
ABSL_NAMESPACE_BEGIN int64_t GetCurrentTimeNanos()
Definition: abseil-cpp/absl/time/clock.cc:78
absl::base_internal::CycleClock::Now
static int64_t Now()
Definition: abseil-cpp/absl/base/internal/cycleclock.cc:63
absl::Now
ABSL_NAMESPACE_BEGIN Time Now()
Definition: abseil-cpp/absl/time/clock.cc:39
timeval
Definition: setup_once.h:113
benchmark::State
Definition: benchmark/include/benchmark/benchmark.h:503
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
BENCHMARK
#define BENCHMARK(n)
Definition: benchmark/include/benchmark/benchmark.h:1170


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:55