• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.regression;
18 
19 import com.google.caliper.Param;
20 import com.google.caliper.Runner;
21 import com.google.caliper.SimpleBenchmark;
22 
23 public class StringToRealBenchmark extends SimpleBenchmark {
24 
25     @Param({
26         "NaN",
27         "-1",
28         "0",
29         "1",
30         "1.2",
31         "-123.45",
32         "-123.45e8",
33         "-123.45e36"
34     }) String string;
35 
timeFloat_parseFloat(int reps)36     public void timeFloat_parseFloat(int reps) {
37         for (int rep = 0; rep < reps; ++rep) {
38             Float.parseFloat(string);
39         }
40     }
41 
timeDouble_parseDouble(int reps)42     public void timeDouble_parseDouble(int reps) {
43         for (int rep = 0; rep < reps; ++rep) {
44             Double.parseDouble(string);
45         }
46     }
47 }
48