Home | History | Annotate | Download | only in benchmarks
      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;
     18 
     19 /**
     20  * How much do various kinds of multiplication cost?
     21  */
     22 public class MultiplicationBenchmark {
     23     public int timeMultiplyIntByConstant10(int reps) {
     24         int result = 1;
     25         for (int i = 0; i < reps; ++i) {
     26             result *= 10;
     27         }
     28         return result;
     29     }
     30     public int timeMultiplyIntByConstant8(int reps) {
     31         int result = 1;
     32         for (int i = 0; i < reps; ++i) {
     33             result *= 8;
     34         }
     35         return result;
     36     }
     37     public int timeMultiplyIntByVariable10(int reps) {
     38         int result = 1;
     39         int factor = 10;
     40         for (int i = 0; i < reps; ++i) {
     41             result *= factor;
     42         }
     43         return result;
     44     }
     45     public int timeMultiplyIntByVariable8(int reps) {
     46         int result = 1;
     47         int factor = 8;
     48         for (int i = 0; i < reps; ++i) {
     49             result *= factor;
     50         }
     51         return result;
     52     }
     53 }
     54