Home | History | Annotate | Download | only in regression
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      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 java.math.BigDecimal;
     20 import java.text.AttributedCharacterIterator;
     21 import java.text.Bidi;
     22 import java.text.DecimalFormat;
     23 
     24 public class BidiBenchmark {
     25 
     26     private static final AttributedCharacterIterator charIter =
     27             DecimalFormat.getInstance().formatToCharacterIterator(new BigDecimal(Math.PI));
     28 
     29     public void time_createBidiFromIter(int reps) {
     30         for (int i = 0; i < reps; i++) {
     31             Bidi bidi = new Bidi(charIter);
     32         }
     33     }
     34 
     35     public void time_createBidiFromCharArray(int reps) {
     36         for (int i = 0; i < reps; i++) {
     37             Bidi bd = new Bidi(new char[]{'s', 's', 's'}, 0, new byte[]{(byte) 1,
     38                     (byte) 2, (byte) 3}, 0, 3, Bidi.DIRECTION_RIGHT_TO_LEFT);
     39         }
     40     }
     41 
     42     public void time_createBidiFromString(int reps) {
     43         for (int i = 0; i < reps; i++) {
     44             Bidi bidi = new Bidi("Hello", Bidi.DIRECTION_LEFT_TO_RIGHT);
     45         }
     46     }
     47 
     48     public void time_reorderVisually(int reps) {
     49         for (int i = 0; i < reps; i++) {
     50             Bidi.reorderVisually(new byte[]{2, 1, 3, 0, 4}, 0,
     51                     new String[]{"H", "e", "l", "l", "o"}, 0, 5);
     52         }
     53     }
     54 
     55     public void time_hebrewBidi(int reps) {
     56         for (int i = 0; i < reps; i++) {
     57             Bidi bd = new Bidi(new char[]{'\u05D0', '\u05D0', '\u05D0'}, 0,
     58                     new byte[]{(byte) -1, (byte) -2, (byte) -3}, 0, 3,
     59                     Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
     60             bd = new Bidi(new char[]{'\u05D0', '\u05D0', '\u05D0'}, 0,
     61                     new byte[]{(byte) -1, (byte) -2, (byte) -3}, 0, 3,
     62                     Bidi.DIRECTION_LEFT_TO_RIGHT);
     63         }
     64     }
     65 
     66     public void time_complicatedOverrideBidi(int reps) {
     67         for (int i = 0; i < reps; i++) {
     68             Bidi bd = new Bidi("a\u05D0a\"a\u05D0\"\u05D0a".toCharArray(), 0,
     69                     new byte[]{0, 0, 0, -3, -3, 2, 2, 0, 3}, 0, 9,
     70                     Bidi.DIRECTION_RIGHT_TO_LEFT);
     71         }
     72     }
     73 
     74     public void time_requiresBidi(int reps) {
     75         for (int i = 0; i < reps; i++) {
     76             Bidi.requiresBidi("\u05D0".toCharArray(), 1, 1);  // false.
     77             Bidi.requiresBidi("\u05D0".toCharArray(), 0, 1);  // true.
     78         }
     79     }
     80 
     81 }
     82