blob: 3bf8c07f6ce3b54ba9225446f7bb757cc39f450f [file] [log] [blame]
Elliott Hughes4a05bef2013-03-11 17:17:02 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "benchmark.h"
18
19#include <time.h>
20
21#if defined(__BIONIC__)
22
23// Used by the horrible android.text.format.Time class, which is used by Calendar. http://b/8270865.
24extern "C" void localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz);
25
26static void BM_time_localtime_tz(int iters) {
27 StartBenchmarkTiming();
28
29 time_t now(time(NULL));
30 tm broken_down_time;
31 for (int i = 0; i < iters; ++i) {
32 localtime_tz(&now, &broken_down_time, "Europe/Berlin");
33 }
34
35 StopBenchmarkTiming();
36}
37BENCHMARK(BM_time_localtime_tz);
Elliott Hughes7634db52014-06-09 18:35:21 -070038
Elliott Hughes4a05bef2013-03-11 17:17:02 -070039#endif
Elliott Hughes7634db52014-06-09 18:35:21 -070040
41static void BM_time_clock_gettime(int iters) {
42 StartBenchmarkTiming();
43
44 struct timespec t;
45 for (int i = 0; i < iters; ++i) {
46 clock_gettime(CLOCK_MONOTONIC, &t);
47 }
48
49 StopBenchmarkTiming();
50}
51BENCHMARK(BM_time_clock_gettime);