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 android.libcore.regression; 18 19 import android.perftests.utils.BenchmarkState; 20 import android.perftests.utils.PerfStatusReporter; 21 22 import androidx.test.filters.LargeTest; 23 24 import junitparams.JUnitParamsRunner; 25 import junitparams.Parameters; 26 27 import org.junit.Rule; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 import java.text.BreakIterator; 32 import java.util.Arrays; 33 import java.util.Collection; 34 import java.util.Locale; 35 36 @RunWith(JUnitParamsRunner.class) 37 @LargeTest 38 public final class BreakIteratorPerfTest { 39 @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); 40 41 public enum Text { 42 LIPSUM( 43 Locale.US, 44 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mollis consequat" 45 + " nisl non pharetra. Praesent pretium vehicula odio sed ultrices. Aenean a" 46 + " felis libero. Vivamus sed commodo nibh. Pellentesque turpis lectus," 47 + " euismod vel ante nec, cursus posuere orci. Suspendisse velit neque," 48 + " fermentum luctus ultrices in, ultrices vitae arcu. Duis tincidunt cursus" 49 + " lorem. Nam ultricies accumsan quam vitae imperdiet. Pellentesque habitant" 50 + " morbi tristique senectus et netus et malesuada fames ac turpis egestas." 51 + " Quisque aliquet pretium nisi, eget laoreet enim molestie sit amet. Class" 52 + " aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos" 53 + " himenaeos.\n" 54 + "Nam dapibus aliquam lacus ac suscipit. Proin in nibh sit amet purus congue" 55 + " laoreet eget quis nisl. Morbi gravida dignissim justo, a venenatis ante" 56 + " pulvinar at. Lorem ipsum dolor sit amet, consectetur adipiscing elit." 57 + " Proin ultrices vestibulum dui, vel aliquam lacus aliquam quis. Duis" 58 + " fringilla sapien ac lacus egestas, vel adipiscing elit euismod. Donec non" 59 + " tellus odio. Donec gravida eu massa ac feugiat. Aliquam erat volutpat." 60 + " Praesent id adipiscing metus, nec laoreet enim. Aliquam vitae posuere" 61 + " turpis. Mauris ac pharetra sem. In at placerat tortor. Vivamus ac vehicula" 62 + " neque. Cras volutpat ullamcorper massa et varius. Praesent sagittis neque" 63 + " vitae nulla euismod pharetra.\n" 64 + "Sed placerat sapien non molestie sollicitudin. Nullam sit amet dictum quam." 65 + " Etiam tincidunt tortor vel pretium vehicula. Praesent fringilla ipsum vel" 66 + " velit luctus dignissim. Nulla massa ligula, mattis in enim et, mattis" 67 + " lacinia odio. Suspendisse tristique urna a orci commodo tempor. Duis" 68 + " lacinia egestas arcu a sollicitudin.\n" 69 + "In ac feugiat lacus. Nunc fermentum eu est at tristique. Pellentesque quis" 70 + " ligula et orci placerat lacinia. Maecenas quis mauris diam. Etiam mi" 71 + " ipsum, tempus in purus quis, euismod faucibus orci. Nulla facilisi." 72 + " Praesent sit amet sapien vel elit porta adipiscing. Phasellus sit amet" 73 + " volutpat diam.\n" 74 + "Proin bibendum elit non lacus pharetra, quis eleifend tellus placerat." 75 + " Nulla facilisi. Maecenas ante diam, pellentesque mattis mattis in, porta" 76 + " ut lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices" 77 + " posuere cubilia Curae; Nunc interdum tristique metus, in scelerisque odio" 78 + " fermentum eget. Cras nec venenatis lacus. Aenean euismod eget metus quis" 79 + " molestie. Cras tincidunt dolor ut massa ornare, in elementum lacus auctor." 80 + " Cras sodales nisl lacus, id ultrices ligula varius at. Sed tristique sit" 81 + " amet tellus vel mollis. Sed sed sollicitudin quam. Sed sed adipiscing" 82 + " risus, et dictum orci. Cras tempor pellentesque turpis et tempus."), 83 LONGPARA( 84 Locale.US, 85 "During dinner, Mr. Bennet scarcely spoke at all; but when the servants were" 86 + " withdrawn, he thought it time to have some conversation with his guest," 87 + " and therefore started a subject in which he expected him to shine, by" 88 + " observing that he seemed very fortunate in his patroness. Lady Catherine" 89 + " de Bourgh's attention to his wishes, and consideration for his comfort," 90 + " appeared very remarkable. Mr. Bennet could not have chosen better. Mr." 91 + " Collins was eloquent in her praise. The subject elevated him to more than" 92 + " usual solemnity of manner, and with a most important aspect he protested" 93 + " that \"he had never in his life witnessed such behaviour in a person of" 94 + " rank--such affability and condescension, as he had himself experienced" 95 + " from Lady Catherine. She had been graciously pleased to approve of both of" 96 + " the discourses which he had already had the honour of preaching before" 97 + " her. She had also asked him twice to dine at Rosings, and had sent for him" 98 + " only the Saturday before, to make up her pool of quadrille in the evening." 99 + " Lady Catherine was reckoned proud by many people he knew, but _he_ had" 100 + " never seen anything but affability in her. She had always spoken to him as" 101 + " she would to any other gentleman; she made not the smallest objection to" 102 + " his joining in the society of the neighbourhood nor to his leaving the" 103 + " parish occasionally for a week or two, to visit his relations. She had" 104 + " even condescended to advise him to marry as soon as he could, provided he" 105 + " chose with discretion; and had once paid him a visit in his humble" 106 + " parsonage, where she had perfectly approved all the alterations he had" 107 + " been making, and had even vouchsafed to suggest some herself--some shelves" 108 + " in the closet up stairs.\""), 109 GERMAN( 110 Locale.GERMANY, 111 "Aber dieser Freiheit setzte endlich der Winter ein Ziel. Draußen auf den Feldern" 112 + " und den hohen Bergen lag der Schnee und Peter wäre in seinem dünnen" 113 + " Leinwandjäckchen bald erfroren. Es war also seine einzige Freude, hinaus" 114 + " vor die Hütte zu treten und den Sperlingen Brotkrümchen zu streuen, was er" 115 + " sich jedesmal an seinem Frühstück absparte. Wenn nun die Vögel so lustig" 116 + " zwitscherten und um ihn herumflogen, da klopfte ihm das Herz vor Lust, und" 117 + " oft gab er ihnen sein ganzes Stück Schwarzbrot, ohne daran zu denken, daß" 118 + " er dafür alsdann selbst hungern müsse."), 119 THAI( 120 Locale.forLanguageTag("th-TH"), 121 "เป็นสำเนียงทางการของภาษาไทย" 122 + " เดิมทีเป็นการผสมผสานกันระหว่างสำเนียงอยุธยาและชาวไทยเชื้อสายจีนรุ่นหลังที่" 123 + "พูดไทยแทนกลุ่มภาษาจีน" 124 + " ลักษณะเด่นคือมีการออกเสียงที่ชัดเจนและแข็งกระด้างซึ่งได้รับอิทธิพลจากภาษาแต" 125 + "้จิ๋ว การออกเสียงพยัญชนะ สระ การผันวรรณยุกต์ที่ในภาษาไทยมาตรฐาน" 126 + " มาจากสำเนียงถิ่นนี้ในขณะที่ภาษาไทยสำเนียงอื่นล้วนเหน่อทั้งสิ้น" 127 + " คำศัพท์ที่ใช้ในสำเนียงกรุงเทพจำนวนมากได้รับมาจากกลุ่มภาษาจีนเช่นคำว่า โป๊," 128 + " เฮ็ง, อาหมวย, อาซิ่ม ซึ่งมาจากภาษาแต้จิ๋ว และจากภาษาจีนเช่น ถู(涂), ชิ่ว(去" 129 + " อ่านว่า\"ชู่\") และคำว่า ทาย(猜 อ่านว่า \"ชาย\") เป็นต้น" 130 + " เนื่องจากสำเนียงกรุงเทพได้รับอิทธิพลมาจากภาษาจีนดังนั้นตัวอักษร \"ร\"" 131 + " มักออกเสียงเหมารวมเป็น \"ล\" หรือคำควบกล่ำบางคำถูกละทิ้งไปด้วยเช่น รู้" 132 + " เป็น ลู้, เรื่อง เป็น เลื่อง หรือ ประเทศ เป็น ปะเทศ" 133 + " เป็นต้นสร้างความลำบากให้แก่ต่างชาติที่ต้องการเรียนภาษาไทย" 134 + " แต่อย่างไรก็ตามผู้ที่พูดสำเนียงถิ่นนี้ก็สามารถออกอักขระภาษาไทยตามมาตรฐานได" 135 + "้อย่างถูกต้องเพียงแต่มักเผลอไม่ค่อยออกเสียง"), 136 THAI2(Locale.forLanguageTag("th-TH"), "this is the word browser in Thai: เบราว์เซอร์"), 137 TABS(Locale.US, "one\t\t\t\t\t\t\t\t\t\t\t\t\t\ttwo\n"), 138 ACCENT(Locale.US, "e\u0301\u00e9\nwhich is:\n\"e\\u0301\\u00e9\""), 139 EMOJI(Locale.US, ">>\ud83d\ude01<<\nwhich is:\n\">>\\ud83d\\ude01<<\""), 140 SPACES(Locale.US, " leading spaces and trailing ones too "), 141 EMPTY(Locale.US, ""), 142 NEWLINE(Locale.US, "\\n:\n"), 143 BIDI( 144 Locale.forLanguageTag("he-IL"), 145 "Sarah שרה is spelled sin ש resh ר heh ה from right to left."); 146 147 final Locale mLocale; 148 final String mText; 149 Text(Locale locale, String text)150 Text(Locale locale, String text) { 151 this.mText = text; 152 this.mLocale = locale; 153 } 154 } 155 getData()156 public static Collection<Object[]> getData() { 157 return Arrays.asList( 158 new Object[][] { 159 {Text.ACCENT}, {Text.BIDI}, {Text.EMOJI}, {Text.EMPTY}, {Text.GERMAN}, 160 {Text.LIPSUM}, {Text.LONGPARA}, {Text.NEWLINE}, {Text.SPACES}, {Text.TABS}, 161 {Text.THAI}, {Text.THAI2} 162 }); 163 } 164 165 @Test 166 @Parameters(method = "getData") timeBreakIterator(Text text)167 public void timeBreakIterator(Text text) { 168 BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); 169 while (state.keepRunning()) { 170 BreakIterator it = BreakIterator.getLineInstance(text.mLocale); 171 it.setText(text.mText); 172 173 while (it.next() != BreakIterator.DONE) { 174 // Keep iterating 175 } 176 } 177 } 178 179 @Test 180 @Parameters(method = "getData") timeIcuBreakIterator(Text text)181 public void timeIcuBreakIterator(Text text) { 182 BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); 183 while (state.keepRunning()) { 184 android.icu.text.BreakIterator it = 185 android.icu.text.BreakIterator.getLineInstance(text.mLocale); 186 it.setText(text.mText); 187 188 while (it.next() != android.icu.text.BreakIterator.DONE) { 189 // Keep iterating 190 } 191 } 192 } 193 } 194