Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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 }