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