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 17package benchmarks.regression; 18 19public class IntConstantDivisionBenchmark { 20 public int timeDivideIntByConstant2(int reps) { 21 int result = 1; 22 for (int i = 0; i < reps; ++i) { 23 result /= 2; 24 } 25 return result; 26 } 27 public int timeDivideIntByConstant8(int reps) { 28 int result = 1; 29 for (int i = 0; i < reps; ++i) { 30 result /= 8; 31 } 32 return result; 33 } 34 public int timeDivideIntByConstant10(int reps) { 35 int result = 1; 36 for (int i = 0; i < reps; ++i) { 37 result /= 10; 38 } 39 return result; 40 } 41 public int timeDivideIntByConstant100(int reps) { 42 int result = 1; 43 for (int i = 0; i < reps; ++i) { 44 result /= 100; 45 } 46 return result; 47 } 48 public int timeDivideIntByConstant100_HandOptimized(int reps) { 49 int result = 1; 50 for (int i = 0; i < reps; ++i) { 51 result = (int) ((0x51eb851fL * result) >>> 37); 52 } 53 return result; 54 } 55 public int timeDivideIntByConstant2048(int reps) { 56 int result = 1; 57 for (int i = 0; i < reps; ++i) { 58 result /= 2048; 59 } 60 return result; 61 } 62 public int timeDivideIntByVariable2(int reps) { 63 int result = 1; 64 int factor = 2; 65 for (int i = 0; i < reps; ++i) { 66 result /= factor; 67 } 68 return result; 69 } 70 public int timeDivideIntByVariable10(int reps) { 71 int result = 1; 72 int factor = 10; 73 for (int i = 0; i < reps; ++i) { 74 result /= factor; 75 } 76 return result; 77 } 78} 79