@@ -57,10 +57,14 @@ public class JRTCompare2Benchmark {
5757 private Object stringLeft ;
5858 private Object stringRightEqual ;
5959 private Object stringRightGreater ;
60- private Object numericStringLeft ;
61- private Object numericStringRightEqual ;
62- private Object numericStringRightGreater ;
60+ private Object plainNumericStringLeft ;
61+ private Object plainNumericStringRightEqual ;
62+ private Object plainNumericStringRightGreater ;
6363 private Object nonNumericString ;
64+ private Object strNumLeft ;
65+ private Object strNumRightEqual ;
66+ private Object strNumRightGreater ;
67+ private Object nonNumericStrNum ;
6468
6569 /**
6670 * Initializes benchmark operands as mutable state fields so the benchmark body
@@ -78,10 +82,14 @@ public void setup() {
7882 this .stringLeft = "alpha" ;
7983 this .stringRightEqual = "alpha" ;
8084 this .stringRightGreater = "bravo" ;
81- this .numericStringLeft = "123" ;
82- this .numericStringRightEqual = "123.0" ;
83- this .numericStringRightGreater = "456" ;
85+ this .plainNumericStringLeft = "123" ;
86+ this .plainNumericStringRightEqual = "123.0" ;
87+ this .plainNumericStringRightGreater = "456" ;
8488 this .nonNumericString = "2x" ;
89+ this .strNumLeft = new StrNum ("123" );
90+ this .strNumRightEqual = new StrNum ("123.0" );
91+ this .strNumRightGreater = new StrNum ("456" );
92+ this .nonNumericStrNum = new StrNum ("2x" );
8593 }
8694
8795 /**
@@ -155,33 +163,66 @@ public boolean stringLessThan() {
155163 }
156164
157165 /**
158- * Measures equality for two numeric string operands.
166+ * Measures equality for two plain numeric-looking {@link String} operands.
159167 *
160168 * @return the comparison result
161169 */
162170 @ Benchmark
163- public boolean numericStringEquals () {
164- return JRT .compare2 (this .numericStringLeft , this .numericStringRightEqual , 0 );
171+ public boolean plainNumericStringEquals () {
172+ return JRT .compare2 (this .plainNumericStringLeft , this .plainNumericStringRightEqual , 0 );
165173 }
166174
167175 /**
168- * Measures less-than comparison for two numeric string operands.
176+ * Measures less-than comparison for two plain numeric-looking {@link String}
177+ * operands.
169178 *
170179 * @return the comparison result
171180 */
172181 @ Benchmark
173- public boolean numericStringLessThan () {
174- return JRT .compare2 (this .numericStringLeft , this .numericStringRightGreater , -1 );
182+ public boolean plainNumericStringLessThan () {
183+ return JRT .compare2 (this .plainNumericStringLeft , this .plainNumericStringRightGreater , -1 );
175184 }
176185
177186 /**
178- * Measures equality for a boxed {@link Long} and a numeric string operand.
187+ * Measures equality for a boxed {@link Long} and a plain numeric-looking
188+ * {@link String} operand.
179189 *
180190 * @return the comparison result
181191 */
182192 @ Benchmark
183- public boolean mixedLongNumericStringEquals () {
184- return JRT .compare2 (this .longLeft , this .numericStringRightEqual , 0 );
193+ public boolean mixedLongPlainNumericStringEquals () {
194+ return JRT .compare2 (this .longLeft , this .plainNumericStringRightEqual , 0 );
195+ }
196+
197+ /**
198+ * Measures equality for two input-derived numeric string operands.
199+ *
200+ * @return the comparison result
201+ */
202+ @ Benchmark
203+ public boolean strNumEquals () {
204+ return JRT .compare2 (this .strNumLeft , this .strNumRightEqual , 0 );
205+ }
206+
207+ /**
208+ * Measures less-than comparison for two input-derived numeric string operands.
209+ *
210+ * @return the comparison result
211+ */
212+ @ Benchmark
213+ public boolean strNumLessThan () {
214+ return JRT .compare2 (this .strNumLeft , this .strNumRightGreater , -1 );
215+ }
216+
217+ /**
218+ * Measures equality for a boxed {@link Long} and an input-derived numeric
219+ * string operand.
220+ *
221+ * @return the comparison result
222+ */
223+ @ Benchmark
224+ public boolean mixedLongStrNumEquals () {
225+ return JRT .compare2 (this .longLeft , this .strNumRightEqual , 0 );
185226 }
186227
187228 /**
@@ -194,4 +235,15 @@ public boolean mixedLongNumericStringEquals() {
194235 public boolean mixedLongNonNumericStringLessThan () {
195236 return JRT .compare2 (this .longLeft , this .nonNumericString , -1 );
196237 }
238+
239+ /**
240+ * Measures fallback string comparison for a numeric operand and a nonnumeric
241+ * input-derived string.
242+ *
243+ * @return the comparison result
244+ */
245+ @ Benchmark
246+ public boolean mixedLongNonNumericStrNumLessThan () {
247+ return JRT .compare2 (this .longLeft , this .nonNumericStrNum , -1 );
248+ }
197249}
0 commit comments