Home | History | Annotate | Download | only in tests
      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  */
     16 
     17 #include "benchmark.h"
     18 
     19 #include <math.h>
     20 
     21 // Avoid optimization.
     22 double d;
     23 double v;
     24 
     25 static void BM_math_sqrt(int iters) {
     26   StartBenchmarkTiming();
     27 
     28   d = 0.0;
     29   v = 2.0;
     30   for (int i = 0; i < iters; ++i) {
     31     d += sqrt(v);
     32   }
     33 
     34   StopBenchmarkTiming();
     35 }
     36 BENCHMARK(BM_math_sqrt);
     37 
     38 static void BM_math_log10(int iters) {
     39   StartBenchmarkTiming();
     40 
     41   d = 0.0;
     42   v = 1234.0;
     43   for (int i = 0; i < iters; ++i) {
     44     d += log10(v);
     45   }
     46 
     47   StopBenchmarkTiming();
     48 }
     49 BENCHMARK(BM_math_log10);
     50 
     51 static void BM_math_logb(int iters) {
     52   StartBenchmarkTiming();
     53 
     54   d = 0.0;
     55   v = 1234.0;
     56   for (int i = 0; i < iters; ++i) {
     57     d += logb(v);
     58   }
     59 
     60   StopBenchmarkTiming();
     61 }
     62 BENCHMARK(BM_math_logb);
     63