Elliott Hughes | 97aba27 | 2013-02-13 16:21:51 -0800 | [diff] [blame] | 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 | import com.google.caliper.Param; |
| 20 | import com.google.caliper.Runner; |
| 21 | import com.google.caliper.SimpleBenchmark; |
| 22 | |
| 23 | /** |
| 24 | * How much do various kinds of multiplication cost? |
| 25 | */ |
| 26 | public class MultiplicationBenchmark extends SimpleBenchmark { |
| 27 | public int timeMultiplyIntByConstant10(int reps) { |
| 28 | int result = 1; |
| 29 | for (int i = 0; i < reps; ++i) { |
| 30 | result *= 10; |
| 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 timeMultiplyIntByVariable10(int reps) { |
| 42 | int result = 1; |
| 43 | int factor = 10; |
| 44 | for (int i = 0; i < reps; ++i) { |
| 45 | result *= factor; |
| 46 | } |
| 47 | return result; |
| 48 | } |
| 49 | public int timeMultiplyIntByVariable8(int reps) { |
| 50 | int result = 1; |
| 51 | int factor = 8; |
| 52 | for (int i = 0; i < reps; ++i) { |
| 53 | result *= factor; |
| 54 | } |
| 55 | return result; |
| 56 | } |
| 57 | } |