Home | History | Annotate | Download | only in benchmarks
      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 
     22 BENCHMARK_NO_ARG(BM_unistd_getpid);
     23 void BM_unistd_getpid::Run(int iters) {
     24   StartBenchmarkTiming();
     25 
     26   for (int i = 0; i < iters; ++i) {
     27     getpid();
     28   }
     29 
     30   StopBenchmarkTiming();
     31 }
     32 
     33 BENCHMARK_NO_ARG(BM_unistd_getpid_syscall);
     34 void BM_unistd_getpid_syscall::Run(int iters) {
     35   StartBenchmarkTiming();
     36 
     37   for (int i = 0; i < iters; ++i) {
     38     syscall(__NR_getpid);
     39   }
     40 
     41   StopBenchmarkTiming();
     42 }
     43 
     44 #if defined(__BIONIC__)
     45 
     46 // Stop GCC optimizing out our pure function.
     47 /* Must not be static! */ pid_t (*gettid_fp)() = gettid;
     48 
     49 BENCHMARK_NO_ARG(BM_unistd_gettid);
     50 void BM_unistd_gettid::Run(int iters) {
     51   StartBenchmarkTiming();
     52 
     53   for (int i = 0; i < iters; ++i) {
     54     gettid_fp();
     55   }
     56 
     57   StopBenchmarkTiming();
     58 }
     59 
     60 #endif
     61 
     62 BENCHMARK_NO_ARG(BM_unistd_gettid_syscall);
     63 void BM_unistd_gettid_syscall::Run(int iters) {
     64   StartBenchmarkTiming();
     65 
     66   for (int i = 0; i < iters; ++i) {
     67     syscall(__NR_gettid);
     68   }
     69 
     70   StopBenchmarkTiming();
     71 }
     72