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 IntegralToStringBenchmark { 20 21 private static final int SMALL = 12; 22 private static final int MEDIUM = 12345; 23 private static final int LARGE = 12345678; 24 25 public void time_IntegerToString_small(int reps) { 26 for (int rep = 0; rep < reps; ++rep) { 27 Integer.toString(SMALL); 28 } 29 } 30 31 public void time_IntegerToString_medium(int reps) { 32 for (int rep = 0; rep < reps; ++rep) { 33 Integer.toString(MEDIUM); 34 } 35 } 36 37 public void time_IntegerToString_large(int reps) { 38 for (int rep = 0; rep < reps; ++rep) { 39 Integer.toString(LARGE); 40 } 41 } 42 43 public void time_IntegerToString2_small(int reps) { 44 for (int rep = 0; rep < reps; ++rep) { 45 Integer.toString(SMALL, 2); 46 } 47 } 48 49 public void time_IntegerToString2_medium(int reps) { 50 for (int rep = 0; rep < reps; ++rep) { 51 Integer.toString(MEDIUM, 2); 52 } 53 } 54 55 public void time_IntegerToString2_large(int reps) { 56 for (int rep = 0; rep < reps; ++rep) { 57 Integer.toString(LARGE, 2); 58 } 59 } 60 61 public void time_IntegerToString10_small(int reps) { 62 for (int rep = 0; rep < reps; ++rep) { 63 Integer.toString(SMALL, 10); 64 } 65 } 66 67 public void time_IntegerToString10_medium(int reps) { 68 for (int rep = 0; rep < reps; ++rep) { 69 Integer.toString(MEDIUM, 10); 70 } 71 } 72 73 public void time_IntegerToString10_large(int reps) { 74 for (int rep = 0; rep < reps; ++rep) { 75 Integer.toString(LARGE, 10); 76 } 77 } 78 79 public void time_IntegerToString16_small(int reps) { 80 for (int rep = 0; rep < reps; ++rep) { 81 Integer.toString(SMALL, 16); 82 } 83 } 84 85 public void time_IntegerToString16_medium(int reps) { 86 for (int rep = 0; rep < reps; ++rep) { 87 Integer.toString(MEDIUM, 16); 88 } 89 } 90 91 public void time_IntegerToString16_large(int reps) { 92 for (int rep = 0; rep < reps; ++rep) { 93 Integer.toString(LARGE, 16); 94 } 95 } 96 97 public void time_IntegerToBinaryString_small(int reps) { 98 for (int rep = 0; rep < reps; ++rep) { 99 Integer.toBinaryString(SMALL); 100 } 101 } 102 103 public void time_IntegerToBinaryString_medium(int reps) { 104 for (int rep = 0; rep < reps; ++rep) { 105 Integer.toBinaryString(MEDIUM); 106 } 107 } 108 109 public void time_IntegerToBinaryString_large(int reps) { 110 for (int rep = 0; rep < reps; ++rep) { 111 Integer.toBinaryString(LARGE); 112 } 113 } 114 115 public void time_IntegerToHexString_small(int reps) { 116 for (int rep = 0; rep < reps; ++rep) { 117 Integer.toHexString(SMALL); 118 } 119 } 120 121 public void time_IntegerToHexString_medium(int reps) { 122 for (int rep = 0; rep < reps; ++rep) { 123 Integer.toHexString(MEDIUM); 124 } 125 } 126 127 public void time_IntegerToHexString_large(int reps) { 128 for (int rep = 0; rep < reps; ++rep) { 129 Integer.toHexString(LARGE); 130 } 131 } 132 133 public void time_StringBuilder_small(int reps) { 134 for (int rep = 0; rep < reps; ++rep) { 135 new StringBuilder().append(SMALL); 136 } 137 } 138 139 public void time_StringBuilder_medium(int reps) { 140 for (int rep = 0; rep < reps; ++rep) { 141 new StringBuilder().append(MEDIUM); 142 } 143 } 144 145 public void time_StringBuilder_large(int reps) { 146 for (int rep = 0; rep < reps; ++rep) { 147 new StringBuilder().append(LARGE); 148 } 149 } 150 151 public void time_Formatter_small(int reps) { 152 for (int rep = 0; rep < reps; ++rep) { 153 String.format("%d", SMALL); 154 } 155 } 156 157 public void time_Formatter_medium(int reps) { 158 for (int rep = 0; rep < reps; ++rep) { 159 String.format("%d", MEDIUM); 160 } 161 } 162 163 public void time_Formatter_large(int reps) { 164 for (int rep = 0; rep < reps; ++rep) { 165 String.format("%d", LARGE); 166 } 167 } 168} 169