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