blob: 1b0d08d72664767bb57c37574a41bfed79a12776 [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
Elliott Hughes625993d2014-07-15 16:53:13 -070017#include <sys/syscall.h>
Elliott Hughes212e0e32014-12-01 16:43:51 -080018#include <sys/time.h>
Elliott Hughes4a05bef2013-03-11 17:17:02 -070019#include <time.h>
Dan Albert3fe15152015-08-11 16:46:26 -070020#include <unistd.h>
Elliott Hughes4a05bef2013-03-11 17:17:02 -070021
Christopher Ferrisdf4942c2015-02-17 19:58:53 -080022#include <benchmark/Benchmark.h>
23
24BENCHMARK_NO_ARG(BM_time_clock_gettime);
25void BM_time_clock_gettime::Run(int iters) {
Elliott Hughes7634db52014-06-09 18:35:21 -070026 StartBenchmarkTiming();
27
Elliott Hughes625993d2014-07-15 16:53:13 -070028 timespec t;
Elliott Hughes7634db52014-06-09 18:35:21 -070029 for (int i = 0; i < iters; ++i) {
30 clock_gettime(CLOCK_MONOTONIC, &t);
31 }
32
33 StopBenchmarkTiming();
34}
Elliott Hughes625993d2014-07-15 16:53:13 -070035
Christopher Ferrisdf4942c2015-02-17 19:58:53 -080036BENCHMARK_NO_ARG(BM_time_clock_gettime_syscall);
37void BM_time_clock_gettime_syscall::Run(int iters) {
Elliott Hughes625993d2014-07-15 16:53:13 -070038 StartBenchmarkTiming();
39
40 timespec t;
41 for (int i = 0; i < iters; ++i) {
42 syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &t);
43 }
44
45 StopBenchmarkTiming();
46}
Elliott Hughes625993d2014-07-15 16:53:13 -070047
Christopher Ferrisdf4942c2015-02-17 19:58:53 -080048BENCHMARK_NO_ARG(BM_time_gettimeofday);
49void BM_time_gettimeofday::Run(int iters) {
Elliott Hughes625993d2014-07-15 16:53:13 -070050 StartBenchmarkTiming();
51
52 timeval tv;
53 for (int i = 0; i < iters; ++i) {
54 gettimeofday(&tv, NULL);
55 }
56
57 StopBenchmarkTiming();
58}
Elliott Hughes625993d2014-07-15 16:53:13 -070059
Christopher Ferrisdf4942c2015-02-17 19:58:53 -080060BENCHMARK_NO_ARG(BM_time_gettimeofday_syscall);
61void BM_time_gettimeofday_syscall::Run(int iters) {
Elliott Hughes625993d2014-07-15 16:53:13 -070062 StartBenchmarkTiming();
63
64 timeval tv;
65 for (int i = 0; i < iters; ++i) {
66 syscall(__NR_gettimeofday, &tv, NULL);
67 }
68
69 StopBenchmarkTiming();
70}
Elliott Hughes625993d2014-07-15 16:53:13 -070071
Christopher Ferrisdf4942c2015-02-17 19:58:53 -080072BENCHMARK_NO_ARG(BM_time_time);
73void BM_time_time::Run(int iters) {
Elliott Hughes625993d2014-07-15 16:53:13 -070074 StartBenchmarkTiming();
75
76 for (int i = 0; i < iters; ++i) {
77 time(NULL);
78 }
79
80 StopBenchmarkTiming();
81}