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 #endif // _WIN32
19 #include <cstdio>
20 
22 #include "benchmark/benchmark.h"
23 
24 namespace {
25 
26 void BM_Clock_Now_AbslTime(benchmark::State& state) {
27  while (state.KeepRunning()) {
28  benchmark::DoNotOptimize(absl::Now());
29  }
30 }
31 BENCHMARK(BM_Clock_Now_AbslTime);
32 
33 void BM_Clock_Now_GetCurrentTimeNanos(benchmark::State& state) {
34  while (state.KeepRunning()) {
35  benchmark::DoNotOptimize(absl::GetCurrentTimeNanos());
36  }
37 }
38 BENCHMARK(BM_Clock_Now_GetCurrentTimeNanos);
39 
40 void BM_Clock_Now_AbslTime_ToUnixNanos(benchmark::State& state) {
41  while (state.KeepRunning()) {
42  benchmark::DoNotOptimize(absl::ToUnixNanos(absl::Now()));
43  }
44 }
45 BENCHMARK(BM_Clock_Now_AbslTime_ToUnixNanos);
46 
47 void BM_Clock_Now_CycleClock(benchmark::State& state) {
48  while (state.KeepRunning()) {
49  benchmark::DoNotOptimize(absl::base_internal::CycleClock::Now());
50  }
51 }
52 BENCHMARK(BM_Clock_Now_CycleClock);
53 
54 #if !defined(_WIN32)
55 static void BM_Clock_Now_gettimeofday(benchmark::State& state) {
56  struct timeval tv;
57  while (state.KeepRunning()) {
58  benchmark::DoNotOptimize(gettimeofday(&tv, nullptr));
59  }
60 }
61 BENCHMARK(BM_Clock_Now_gettimeofday);
62 
63 static void BM_Clock_Now_clock_gettime(benchmark::State& state) {
64  struct timespec ts;
65  while (state.KeepRunning()) {
66  benchmark::DoNotOptimize(clock_gettime(CLOCK_REALTIME, &ts));
67  }
68 }
69 BENCHMARK(BM_Clock_Now_clock_gettime);
70 #endif // _WIN32
71 
72 } // namespace
Time Now()
Definition: clock.cc:37
int64_t GetCurrentTimeNanos()
Definition: clock.cc:74
int64_t ToUnixNanos(Time t)
Definition: time.cc:237


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:19:56