1 /* 2 * Copyright (C) 2014 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 <sys/syscall.h> 18 #include <unistd.h> 19 20 #include <benchmark/benchmark.h> 21 #include "util.h" 22 BM_unistd_getpid(benchmark::State & state)23static void BM_unistd_getpid(benchmark::State& state) { 24 while (state.KeepRunning()) { 25 getpid(); 26 } 27 } 28 BIONIC_BENCHMARK(BM_unistd_getpid); 29 BM_unistd_getpid_syscall(benchmark::State & state)30static void BM_unistd_getpid_syscall(benchmark::State& state) { 31 while (state.KeepRunning()) { 32 syscall(__NR_getpid); 33 } 34 } 35 BIONIC_BENCHMARK(BM_unistd_getpid_syscall); 36 37 #if defined(__BIONIC__) 38 39 // Stop GCC optimizing out our pure function. 40 /* Must not be static! */ pid_t (*gettid_fp)() = gettid; 41 BM_unistd_gettid(benchmark::State & state)42static void BM_unistd_gettid(benchmark::State& state) { 43 while (state.KeepRunning()) { 44 gettid_fp(); 45 } 46 } 47 BIONIC_BENCHMARK(BM_unistd_gettid); 48 49 #endif 50 BM_unistd_gettid_syscall(benchmark::State & state)51void BM_unistd_gettid_syscall(benchmark::State& state) { 52 while (state.KeepRunning()) { 53 syscall(__NR_gettid); 54 } 55 } 56 BIONIC_BENCHMARK(BM_unistd_gettid_syscall); 57