Home | History | Annotate | Download | only in regression
      1 /*
      2  * Copyright (C) 2010 Google Inc.
      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 package benchmarks.regression;
     18 
     19 public class IntConstantMultiplicationBenchmark {
     20     public int timeMultiplyIntByConstant6(int reps) {
     21         int result = 1;
     22         for (int i = 0; i < reps; ++i) {
     23             result *= 6;
     24         }
     25         return result;
     26     }
     27     public int timeMultiplyIntByConstant7(int reps) {
     28         int result = 1;
     29         for (int i = 0; i < reps; ++i) {
     30             result *= 7;
     31         }
     32         return result;
     33     }
     34     public int timeMultiplyIntByConstant8(int reps) {
     35         int result = 1;
     36         for (int i = 0; i < reps; ++i) {
     37             result *= 8;
     38         }
     39         return result;
     40     }
     41     public int timeMultiplyIntByConstant8_Shift(int reps) {
     42         int result = 1;
     43         for (int i = 0; i < reps; ++i) {
     44             result <<= 3;
     45         }
     46         return result;
     47     }
     48     public int timeMultiplyIntByConstant10(int reps) {
     49         int result = 1;
     50         for (int i = 0; i < reps; ++i) {
     51             result *= 10;
     52         }
     53         return result;
     54     }
     55     public int timeMultiplyIntByConstant10_Shift(int reps) {
     56         int result = 1;
     57         for (int i = 0; i < reps; ++i) {
     58             result = (result + (result << 2)) << 1;
     59         }
     60         return result;
     61     }
     62     public int timeMultiplyIntByConstant2047(int reps) {
     63         int result = 1;
     64         for (int i = 0; i < reps; ++i) {
     65             result *= 2047;
     66         }
     67         return result;
     68     }
     69     public int timeMultiplyIntByConstant2048(int reps) {
     70         int result = 1;
     71         for (int i = 0; i < reps; ++i) {
     72             result *= 2048;
     73         }
     74         return result;
     75     }
     76     public int timeMultiplyIntByConstant2049(int reps) {
     77         int result = 1;
     78         for (int i = 0; i < reps; ++i) {
     79             result *= 2049;
     80         }
     81         return result;
     82     }
     83     public int timeMultiplyIntByVariable10(int reps) {
     84         int result = 1;
     85         int factor = 10;
     86         for (int i = 0; i < reps; ++i) {
     87             result *= factor;
     88         }
     89         return result;
     90     }
     91     public int timeMultiplyIntByVariable8(int reps) {
     92         int result = 1;
     93         int factor = 8;
     94         for (int i = 0; i < reps; ++i) {
     95             result *= factor;
     96         }
     97         return result;
     98     }
     99 }
    100