Home | History | Annotate | Download | only in regression
      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 
     17 package benchmarks.regression;
     18 
     19 public class RealToStringBenchmark {
     20 
     21     private static final float SMALL  = -123.45f;
     22     private static final float MEDIUM = -123.45e8f;
     23     private static final float LARGE  = -123.45e36f;
     24 
     25     public void timeFloat_toString_NaN(int reps) {
     26         for (int rep = 0; rep < reps; ++rep) {
     27             Float.toString(Float.NaN);
     28         }
     29     }
     30 
     31     public void timeFloat_toString_NEGATIVE_INFINITY(int reps) {
     32         for (int rep = 0; rep < reps; ++rep) {
     33             Float.toString(Float.NEGATIVE_INFINITY);
     34         }
     35     }
     36 
     37     public void timeFloat_toString_POSITIVE_INFINITY(int reps) {
     38         for (int rep = 0; rep < reps; ++rep) {
     39             Float.toString(Float.POSITIVE_INFINITY);
     40         }
     41     }
     42 
     43     public void timeFloat_toString_zero(int reps) {
     44         for (int rep = 0; rep < reps; ++rep) {
     45             Float.toString(0.0f);
     46         }
     47     }
     48 
     49     public void timeFloat_toString_minusZero(int reps) {
     50         for (int rep = 0; rep < reps; ++rep) {
     51             Float.toString(-0.0f);
     52         }
     53     }
     54 
     55     public void timeFloat_toString_small(int reps) {
     56         for (int rep = 0; rep < reps; ++rep) {
     57             Float.toString(SMALL);
     58         }
     59     }
     60 
     61     public void timeFloat_toString_medium(int reps) {
     62         for (int rep = 0; rep < reps; ++rep) {
     63             Float.toString(MEDIUM);
     64         }
     65     }
     66 
     67     public void timeFloat_toString_large(int reps) {
     68         for (int rep = 0; rep < reps; ++rep) {
     69             Float.toString(LARGE);
     70         }
     71     }
     72 
     73     public void timeStringBuilder_small(int reps) {
     74         for (int rep = 0; rep < reps; ++rep) {
     75             new StringBuilder().append(SMALL);
     76         }
     77     }
     78 
     79     public void timeStringBuilder_medium(int reps) {
     80         for (int rep = 0; rep < reps; ++rep) {
     81             new StringBuilder().append(MEDIUM);
     82         }
     83     }
     84 
     85     public void timeStringBuilder_large(int reps) {
     86         for (int rep = 0; rep < reps; ++rep) {
     87             new StringBuilder().append(LARGE);
     88         }
     89     }
     90 
     91     public void timeFormatter_small(int reps) {
     92         for (int rep = 0; rep < reps; ++rep) {
     93             String.format("%f", SMALL);
     94         }
     95     }
     96 
     97     public void timeFormatter_medium(int reps) {
     98         for (int rep = 0; rep < reps; ++rep) {
     99             String.format("%f", MEDIUM);
    100         }
    101     }
    102 
    103     public void timeFormatter_large(int reps) {
    104         for (int rep = 0; rep < reps; ++rep) {
    105             String.format("%f", LARGE);
    106         }
    107     }
    108 
    109     public void timeFormatter_dot2f_small(int reps) {
    110         for (int rep = 0; rep < reps; ++rep) {
    111             String.format("%.2f", SMALL);
    112         }
    113     }
    114 
    115     public void timeFormatter_dot2f_medium(int reps) {
    116         for (int rep = 0; rep < reps; ++rep) {
    117             String.format("%.2f", MEDIUM);
    118         }
    119     }
    120 
    121     public void timeFormatter_dot2f_large(int reps) {
    122         for (int rep = 0; rep < reps; ++rep) {
    123             String.format("%.2f", LARGE);
    124         }
    125     }
    126 }
    127