Home | History | Annotate | Download | only in regression
      1 /*
      2  * Copyright (C) 2014 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 com.google.caliper.Param;
     20 import java.text.BreakIterator;
     21 import java.util.Locale;
     22 
     23 public final class BreakIteratorBenchmark {
     24 
     25     public static enum Text {
     26         LIPSUM(Locale.US, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mollis consequat nisl non pharetra. Praesent pretium vehicula odio sed ultrices. Aenean a felis libero. Vivamus sed commodo nibh. Pellentesque turpis lectus, euismod vel ante nec, cursus posuere orci. Suspendisse velit neque, fermentum luctus ultrices in, ultrices vitae arcu. Duis tincidunt cursus lorem. Nam ultricies accumsan quam vitae imperdiet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque aliquet pretium nisi, eget laoreet enim molestie sit amet. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.\nNam dapibus aliquam lacus ac suscipit. Proin in nibh sit amet purus congue laoreet eget quis nisl. Morbi gravida dignissim justo, a venenatis ante pulvinar at. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ultrices vestibulum dui, vel aliquam lacus aliquam quis. Duis fringilla sapien ac lacus egestas, vel adipiscing elit euismod. Donec non tellus odio. Donec gravida eu massa ac feugiat. Aliquam erat volutpat. Praesent id adipiscing metus, nec laoreet enim. Aliquam vitae posuere turpis. Mauris ac pharetra sem. In at placerat tortor. Vivamus ac vehicula neque. Cras volutpat ullamcorper massa et varius. Praesent sagittis neque vitae nulla euismod pharetra.\nSed placerat sapien non molestie sollicitudin. Nullam sit amet dictum quam. Etiam tincidunt tortor vel pretium vehicula. Praesent fringilla ipsum vel velit luctus dignissim. Nulla massa ligula, mattis in enim et, mattis lacinia odio. Suspendisse tristique urna a orci commodo tempor. Duis lacinia egestas arcu a sollicitudin.\nIn ac feugiat lacus. Nunc fermentum eu est at tristique. Pellentesque quis ligula et orci placerat lacinia. Maecenas quis mauris diam. Etiam mi ipsum, tempus in purus quis, euismod faucibus orci. Nulla facilisi. Praesent sit amet sapien vel elit porta adipiscing. Phasellus sit amet volutpat diam.\nProin bibendum elit non lacus pharetra, quis eleifend tellus placerat. Nulla facilisi. Maecenas ante diam, pellentesque mattis mattis in, porta ut lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc interdum tristique metus, in scelerisque odio fermentum eget. Cras nec venenatis lacus. Aenean euismod eget metus quis molestie. Cras tincidunt dolor ut massa ornare, in elementum lacus auctor. Cras sodales nisl lacus, id ultrices ligula varius at. Sed tristique sit amet tellus vel mollis. Sed sed sollicitudin quam. Sed sed adipiscing risus, et dictum orci. Cras tempor pellentesque turpis et tempus."),
     27         LONGPARA(Locale.US, "During dinner, Mr. Bennet scarcely spoke at all; but when the servants were withdrawn, he thought it time to have some conversation with his guest, and therefore started a subject in which he expected him to shine, by observing that he seemed very fortunate in his patroness. Lady Catherine de Bourgh's attention to his wishes, and consideration for his comfort, appeared very remarkable. Mr. Bennet could not have chosen better. Mr. Collins was eloquent in her praise. The subject elevated him to more than usual solemnity of manner, and with a most important aspect he protested that \"he had never in his life witnessed such behaviour in a person of rank--such affability and condescension, as he had himself experienced from Lady Catherine. She had been graciously pleased to approve of both of the discourses which he had already had the honour of preaching before her. She had also asked him twice to dine at Rosings, and had sent for him only the Saturday before, to make up her pool of quadrille in the evening. Lady Catherine was reckoned proud by many people he knew, but _he_ had never seen anything but affability in her. She had always spoken to him as she would to any other gentleman; she made not the smallest objection to his joining in the society of the neighbourhood nor to his leaving the parish occasionally for a week or two, to visit his relations. She had even condescended to advise him to marry as soon as he could, provided he chose with discretion; and had once paid him a visit in his humble parsonage, where she had perfectly approved all the alterations he had been making, and had even vouchsafed to suggest some herself--some shelves in the closet up stairs.\""),
     28         GERMAN(Locale.GERMANY, "Aber dieser Freiheit setzte endlich der Winter ein Ziel. Drauen auf den Feldern und den hohen Bergen lag der Schnee und Peter wre in seinem dnnen Leinwandjckchen bald erfroren. Es war also seine einzige Freude, hinaus vor die Htte zu treten und den Sperlingen Brotkrmchen zu streuen, was er sich jedesmal an seinem Frhstck absparte. Wenn nun die Vgel so lustig zwitscherten und um ihn herumflogen, da klopfte ihm das Herz vor Lust, und oft gab er ihnen sein ganzes Stck Schwarzbrot, ohne daran zu denken, da er dafr alsdann selbst hungern msse."),
     29         THAI(Locale.forLanguageTag("th-TH"), "        , , ,    (), ( \"\")  (  \"\")   \"\"  \"\"    ,         "),
     30         THAI2(Locale.forLanguageTag("th-TH"), "this is the word browser in Thai: "),
     31         TABS(Locale.US, "one\t\t\t\t\t\t\t\t\t\t\t\t\t\ttwo\n"),
     32         ACCENT(Locale.US, "e\u0301\u00e9\nwhich is:\n\"e\\u0301\\u00e9\""),
     33         EMOJI(Locale.US, ">>\ud83d\ude01<<\nwhich is:\n\">>\\ud83d\\ude01<<\""),
     34         SPACES(Locale.US, "     leading spaces      and trailing ones too      "),
     35         EMPTY(Locale.US, ""),
     36         NEWLINE(Locale.US, "\\n:\n"),
     37         BIDI(Locale.forLanguageTag("he-IL"), "Sarah  is spelled sin  resh  heh  from right to left.");
     38 
     39         final Locale locale;
     40         final String text;
     41 
     42         Text(Locale locale, String text) {
     43             this.text  = text;
     44             this.locale = locale;
     45         }
     46     }
     47 
     48     @Param private Text text;
     49 
     50     public void timeBreakIterator(int nreps) {
     51         for (int i = 0;  i < nreps; ++i) {
     52             BreakIterator it = BreakIterator.getLineInstance(text.locale);
     53             it.setText(text.text);
     54 
     55             while (it.next() != BreakIterator.DONE) {
     56             }
     57         }
     58     }
     59 
     60     public void timeIcuBreakIterator(int nreps) {
     61         for (int i = 0; i < nreps; ++i) {
     62             android.icu.text.BreakIterator it =
     63                 android.icu.text.BreakIterator.getLineInstance(text.locale);
     64             it.setText(text.text);
     65 
     66             while (it.next() != android.icu.text.BreakIterator.DONE) {
     67             }
     68         }
     69     }
     70 }
     71