]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/blob - benchmarks/time_benchmark.cpp
Build our benchmarks against glibc too.
[android-sdk/platform-bionic.git] / benchmarks / time_benchmark.cpp
1 /*
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  */
17 #include "benchmark.h"
19 #include <unistd.h>
20 #include <sys/syscall.h>
21 #include <sys/time.h>
22 #include <time.h>
24 static void BM_time_clock_gettime(int iters) {
25   StartBenchmarkTiming();
27   timespec t;
28   for (int i = 0; i < iters; ++i) {
29     clock_gettime(CLOCK_MONOTONIC, &t);
30   }
32   StopBenchmarkTiming();
33 }
34 BENCHMARK(BM_time_clock_gettime);
36 static void BM_time_clock_gettime_syscall(int iters) {
37   StartBenchmarkTiming();
39   timespec t;
40   for (int i = 0; i < iters; ++i) {
41     syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &t);
42   }
44   StopBenchmarkTiming();
45 }
46 BENCHMARK(BM_time_clock_gettime_syscall);
48 static void BM_time_gettimeofday(int iters) {
49   StartBenchmarkTiming();
51   timeval tv;
52   for (int i = 0; i < iters; ++i) {
53     gettimeofday(&tv, NULL);
54   }
56   StopBenchmarkTiming();
57 }
58 BENCHMARK(BM_time_gettimeofday);
60 static void BM_time_gettimeofday_syscall(int iters) {
61   StartBenchmarkTiming();
63   timeval tv;
64   for (int i = 0; i < iters; ++i) {
65     syscall(__NR_gettimeofday, &tv, NULL);
66   }
68   StopBenchmarkTiming();
69 }
70 BENCHMARK(BM_time_gettimeofday_syscall);
72 static void BM_time_time(int iters) {
73   StartBenchmarkTiming();
75   for (int i = 0; i < iters; ++i) {
76     time(NULL);
77   }
79   StopBenchmarkTiming();
80 }
81 BENCHMARK(BM_time_time);