| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.text; |
| 18 |
|
| 19 |
import android.perftests.utils.BenchmarkState; |
| 20 |
import android.perftests.utils.PerfStatusReporter; |
| 21 |
|
| 22 |
import androidx.test.filters.LargeTest; |
| 23 |
import androidx.test.runner.AndroidJUnit4; |
| 24 |
|
| 25 |
import org.junit.Before; |
| 26 |
import org.junit.Rule; |
| 27 |
import org.junit.Test; |
| 28 |
import org.junit.runner.RunWith; |
| 29 |
|
| 30 |
@LargeTest |
| 31 |
@RunWith(AndroidJUnit4.class) |
| 32 |
public class PrecomputedTextPerfTest { |
| 33 |
private static final int WORD_LENGTH = 9; |
| 34 |
private static final int WORDS_IN_LINE = 8; |
| 35 |
private static final boolean NO_STYLE_TEXT = false; |
| 36 |
private static final boolean STYLE_TEXT = true; |
| 37 |
|
| 38 |
private static TextPaint PAINT = new TextPaint(); |
| 39 |
private static final int TEXT_WIDTH = WORDS_IN_LINE * WORD_LENGTH * (int) PAINT.getTextSize(); |
| 40 |
|
| 41 |
public PrecomputedTextPerfTest() {} |
| 42 |
|
| 43 |
@Rule |
| 44 |
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); |
| 45 |
|
| 46 |
private TextPerfUtils mTextUtil = new TextPerfUtils(); |
| 47 |
|
| 48 |
@Before |
| 49 |
public void setUp() { |
| 50 |
mTextUtil.resetRandom(0 ); |
| 51 |
} |
| 52 |
|
| 53 |
@Test |
| 54 |
public void testCreate_NoStyled_Hyphenation() { |
| 55 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 56 |
final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) |
| 57 |
.setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) |
| 58 |
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) |
| 59 |
.build(); |
| 60 |
|
| 61 |
while (state.keepRunning()) { |
| 62 |
state.pauseTiming(); |
| 63 |
final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); |
| 64 |
state.resumeTiming(); |
| 65 |
|
| 66 |
PrecomputedText.create(text, param); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
@Test |
| 71 |
public void testCreate_NoStyled_NoHyphenation() { |
| 72 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 73 |
final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) |
| 74 |
.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) |
| 75 |
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) |
| 76 |
.build(); |
| 77 |
|
| 78 |
while (state.keepRunning()) { |
| 79 |
state.pauseTiming(); |
| 80 |
final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); |
| 81 |
state.resumeTiming(); |
| 82 |
|
| 83 |
PrecomputedText.create(text, param); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
@Test |
| 88 |
public void testCreate_NoStyled_Hyphenation_WidthOnly() { |
| 89 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 90 |
final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) |
| 91 |
.setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) |
| 92 |
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) |
| 93 |
.build(); |
| 94 |
|
| 95 |
while (state.keepRunning()) { |
| 96 |
state.pauseTiming(); |
| 97 |
final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); |
| 98 |
state.resumeTiming(); |
| 99 |
|
| 100 |
PrecomputedText.create(text, param); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
@Test |
| 105 |
public void testCreate_NoStyled_NoHyphenation_WidthOnly() { |
| 106 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 107 |
final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) |
| 108 |
.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) |
| 109 |
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) |
| 110 |
.build(); |
| 111 |
|
| 112 |
while (state.keepRunning()) { |
| 113 |
state.pauseTiming(); |
| 114 |
final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); |
| 115 |
state.resumeTiming(); |
| 116 |
|
| 117 |
PrecomputedText.create(text, param); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
@Test |
| 122 |
public void testCreate_Styled_Hyphenation() { |
| 123 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 124 |
final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) |
| 125 |
.setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) |
| 126 |
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) |
| 127 |
.build(); |
| 128 |
|
| 129 |
while (state.keepRunning()) { |
| 130 |
state.pauseTiming(); |
| 131 |
final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); |
| 132 |
state.resumeTiming(); |
| 133 |
|
| 134 |
PrecomputedText.create(text, param); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
@Test |
| 139 |
public void testCreate_Styled_NoHyphenation() { |
| 140 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 141 |
final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) |
| 142 |
.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) |
| 143 |
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) |
| 144 |
.build(); |
| 145 |
|
| 146 |
while (state.keepRunning()) { |
| 147 |
state.pauseTiming(); |
| 148 |
final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); |
| 149 |
state.resumeTiming(); |
| 150 |
|
| 151 |
PrecomputedText.create(text, param); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
@Test |
| 156 |
public void testCreate_Styled_Hyphenation_WidthOnly() { |
| 157 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 158 |
final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) |
| 159 |
.setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) |
| 160 |
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) |
| 161 |
.build(); |
| 162 |
|
| 163 |
while (state.keepRunning()) { |
| 164 |
state.pauseTiming(); |
| 165 |
final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); |
| 166 |
state.resumeTiming(); |
| 167 |
|
| 168 |
PrecomputedText.create(text, param); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
@Test |
| 173 |
public void testCreate_Styled_NoHyphenation_WidthOnly() { |
| 174 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 175 |
final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) |
| 176 |
.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) |
| 177 |
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) |
| 178 |
.build(); |
| 179 |
|
| 180 |
while (state.keepRunning()) { |
| 181 |
state.pauseTiming(); |
| 182 |
final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); |
| 183 |
state.resumeTiming(); |
| 184 |
|
| 185 |
PrecomputedText.create(text, param); |
| 186 |
} |
| 187 |
} |
| 188 |
} |