29 #include "benchmark/benchmark.h" 37 void BM_Time_Arithmetic(benchmark::State& state) {
41 while (state.KeepRunning()) {
42 benchmark::DoNotOptimize(t += nano);
43 benchmark::DoNotOptimize(t -= sec);
46 BENCHMARK(BM_Time_Arithmetic);
52 void BM_Time_Difference(benchmark::State& state) {
56 while (state.KeepRunning()) {
57 benchmark::DoNotOptimize(diff += end - start);
60 BENCHMARK(BM_Time_Difference);
72 void BM_Time_ToDateTime_Absl(benchmark::State& state) {
77 while (state.KeepRunning()) {
80 benchmark::DoNotOptimize(t.
In(tz));
83 BENCHMARK(BM_Time_ToDateTime_Absl);
85 void BM_Time_ToDateTime_Libc(benchmark::State& state) {
87 time_t t = 1384569027;
88 time_t t2 = 1418962578;
89 while (state.KeepRunning()) {
94 benchmark::DoNotOptimize(localtime_r(&t, &tm));
96 benchmark::DoNotOptimize(localtime_s(&tm, &t));
100 BENCHMARK(BM_Time_ToDateTime_Libc);
102 void BM_Time_ToDateTimeUTC_Absl(benchmark::State& state) {
105 while (state.KeepRunning()) {
107 benchmark::DoNotOptimize(t.
In(tz));
110 BENCHMARK(BM_Time_ToDateTimeUTC_Absl);
112 void BM_Time_ToDateTimeUTC_Libc(benchmark::State& state) {
113 time_t t = 1384569027;
114 while (state.KeepRunning()) {
118 benchmark::DoNotOptimize(gmtime_r(&t, &tm));
120 benchmark::DoNotOptimize(gmtime_s(&tm, &t));
124 BENCHMARK(BM_Time_ToDateTimeUTC_Libc);
130 void BM_Time_FromUnixMicros(benchmark::State& state) {
132 while (state.KeepRunning()) {
137 BENCHMARK(BM_Time_FromUnixMicros);
139 void BM_Time_ToUnixNanos(benchmark::State& state) {
141 while (state.KeepRunning()) {
145 BENCHMARK(BM_Time_ToUnixNanos);
147 void BM_Time_ToUnixMicros(benchmark::State& state) {
149 while (state.KeepRunning()) {
153 BENCHMARK(BM_Time_ToUnixMicros);
155 void BM_Time_ToUnixMillis(benchmark::State& state) {
157 while (state.KeepRunning()) {
161 BENCHMARK(BM_Time_ToUnixMillis);
163 void BM_Time_ToUnixSeconds(benchmark::State& state) {
165 while (state.KeepRunning()) {
169 BENCHMARK(BM_Time_ToUnixSeconds);
182 void BM_Time_FromCivil_Absl(benchmark::State& state) {
186 while (state.KeepRunning()) {
195 BENCHMARK(BM_Time_FromCivil_Absl);
197 void BM_Time_FromCivil_Libc(benchmark::State& state) {
200 while (state.KeepRunning()) {
203 tm.tm_year = 2014 - 1900;
210 tm.tm_year = 2013 - 1900;
222 BENCHMARK(BM_Time_FromCivil_Libc);
224 void BM_Time_FromCivilUTC_Absl(benchmark::State& state) {
226 while (state.KeepRunning()) {
230 BENCHMARK(BM_Time_FromCivilUTC_Absl);
232 void BM_Time_FromCivilDay0_Absl(benchmark::State& state) {
236 while (state.KeepRunning()) {
245 BENCHMARK(BM_Time_FromCivilDay0_Absl);
247 void BM_Time_FromCivilDay0_Libc(benchmark::State& state) {
250 while (state.KeepRunning()) {
253 tm.tm_year = 2014 - 1900;
260 tm.tm_year = 2013 - 1900;
272 BENCHMARK(BM_Time_FromCivilDay0_Libc);
278 void BM_Time_ToTimespec(benchmark::State& state) {
280 while (state.KeepRunning()) {
284 BENCHMARK(BM_Time_ToTimespec);
286 void BM_Time_FromTimespec(benchmark::State& state) {
288 while (state.KeepRunning()) {
289 if (++ts.tv_nsec == 1000 * 1000 * 1000) {
296 BENCHMARK(BM_Time_FromTimespec);
302 void BM_Time_InfiniteFuture(benchmark::State& state) {
303 while (state.KeepRunning()) {
307 BENCHMARK(BM_Time_InfiniteFuture);
309 void BM_Time_InfinitePast(benchmark::State& state) {
310 while (state.KeepRunning()) {
314 BENCHMARK(BM_Time_InfinitePast);
timespec ToTimespec(Duration d)
constexpr Time InfiniteFuture()
int64_t ToUnixMillis(Time t)
int64_t ToUnixMicros(Time t)
constexpr Time FromUnixSeconds(int64_t s)
constexpr Time UnixEpoch()
constexpr Time FromUnixMicros(int64_t us)
absl::Time TimeFromTimespec(timespec ts)
void swap(absl::InlinedVector< T, N, A > &a, absl::InlinedVector< T, N, A > &b) noexcept(noexcept(a.swap(b)))
int64_t ToUnixSeconds(Time t)
constexpr Duration Seconds(int64_t n)
Time FromCivil(CivilSecond ct, TimeZone tz)
TimeZone LoadTimeZone(const std::string &name)
constexpr Duration Nanoseconds(int64_t n)
Breakdown In(TimeZone tz) const
int64_t ToUnixNanos(Time t)
constexpr Time InfinitePast()