clock_benchmark.cc
Go to the documentation of this file.
00001 // Copyright 2018 The Abseil Authors.
00002 // Licensed under the Apache License, Version 2.0 (the "License");
00003 // you may not use this file except in compliance with the License.
00004 // You may obtain a copy of the License at
00005 //
00006 //      https://www.apache.org/licenses/LICENSE-2.0
00007 //
00008 // Unless required by applicable law or agreed to in writing, software
00009 // distributed under the License is distributed on an "AS IS" BASIS,
00010 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00011 // See the License for the specific language governing permissions and
00012 // limitations under the License.
00013 
00014 #include "absl/time/clock.h"
00015 
00016 #if !defined(_WIN32)
00017 #include <sys/time.h>
00018 #endif  // _WIN32
00019 #include <cstdio>
00020 
00021 #include "absl/base/internal/cycleclock.h"
00022 #include "benchmark/benchmark.h"
00023 
00024 namespace {
00025 
00026 void BM_Clock_Now_AbslTime(benchmark::State& state) {
00027   while (state.KeepRunning()) {
00028     benchmark::DoNotOptimize(absl::Now());
00029   }
00030 }
00031 BENCHMARK(BM_Clock_Now_AbslTime);
00032 
00033 void BM_Clock_Now_GetCurrentTimeNanos(benchmark::State& state) {
00034   while (state.KeepRunning()) {
00035     benchmark::DoNotOptimize(absl::GetCurrentTimeNanos());
00036   }
00037 }
00038 BENCHMARK(BM_Clock_Now_GetCurrentTimeNanos);
00039 
00040 void BM_Clock_Now_AbslTime_ToUnixNanos(benchmark::State& state) {
00041   while (state.KeepRunning()) {
00042     benchmark::DoNotOptimize(absl::ToUnixNanos(absl::Now()));
00043   }
00044 }
00045 BENCHMARK(BM_Clock_Now_AbslTime_ToUnixNanos);
00046 
00047 void BM_Clock_Now_CycleClock(benchmark::State& state) {
00048   while (state.KeepRunning()) {
00049     benchmark::DoNotOptimize(absl::base_internal::CycleClock::Now());
00050   }
00051 }
00052 BENCHMARK(BM_Clock_Now_CycleClock);
00053 
00054 #if !defined(_WIN32)
00055 static void BM_Clock_Now_gettimeofday(benchmark::State& state) {
00056   struct timeval tv;
00057   while (state.KeepRunning()) {
00058     benchmark::DoNotOptimize(gettimeofday(&tv, nullptr));
00059   }
00060 }
00061 BENCHMARK(BM_Clock_Now_gettimeofday);
00062 
00063 static void BM_Clock_Now_clock_gettime(benchmark::State& state) {
00064   struct timespec ts;
00065   while (state.KeepRunning()) {
00066     benchmark::DoNotOptimize(clock_gettime(CLOCK_REALTIME, &ts));
00067   }
00068 }
00069 BENCHMARK(BM_Clock_Now_clock_gettime);
00070 #endif  // _WIN32
00071 
00072 }  // namespace


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