Loading apct-tests/perftests/core/src/android/text/MeasuredTextMemoryUsageTest.java→apct-tests/perftests/core/src/android/text/PrecomputedTextMemoryUsageTest.java +34 −22 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ import java.util.Random; @LargeTest @RunWith(AndroidJUnit4.class) public class MeasuredTextMemoryUsageTest { public class PrecomputedTextMemoryUsageTest { private static final int WORD_LENGTH = 9; // Random word has 9 characters. private static final boolean NO_STYLE_TEXT = false; Loading @@ -53,7 +53,7 @@ public class MeasuredTextMemoryUsageTest { private static int TRIAL_COUNT = 100; public MeasuredTextMemoryUsageTest() {} public PrecomputedTextMemoryUsageTest() {} private TextPerfUtils mTextUtil = new TextPerfUtils(); Loading @@ -77,13 +77,16 @@ public class MeasuredTextMemoryUsageTest { @Test public void testMemoryUsage_NoHyphenation() { int[] memories = new int[TRIAL_COUNT]; // Report median of randomly generated MeasuredText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build().getMemoryUsage(); .build(); // Report median of randomly generated PrecomputedText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = PrecomputedText.create( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), param) .getMemoryUsage(); } reportMemoryUsage(median(memories), "MemoryUsage_NoHyphenation"); } Loading @@ -91,13 +94,16 @@ public class MeasuredTextMemoryUsageTest { @Test public void testMemoryUsage_Hyphenation() { int[] memories = new int[TRIAL_COUNT]; // Report median of randomly generated MeasuredText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build().getMemoryUsage(); .build(); // Report median of randomly generated PrecomputedText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = PrecomputedText.create( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), param) .getMemoryUsage(); } reportMemoryUsage(median(memories), "MemoryUsage_Hyphenation"); } Loading @@ -105,13 +111,16 @@ public class MeasuredTextMemoryUsageTest { @Test public void testMemoryUsage_NoHyphenation_WidthOnly() { int[] memories = new int[TRIAL_COUNT]; // Report median of randomly generated MeasuredText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(false /* width only */).getMemoryUsage(); .build(); // Report median of randomly generated PrecomputedText. for (int i = 0; i < TRIAL_COUNT; ++i) { CharSequence cs = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); memories[i] = PrecomputedText.createWidthOnly(cs, param, 0, cs.length()) .getMemoryUsage(); } reportMemoryUsage(median(memories), "MemoryUsage_NoHyphenation_WidthOnly"); } Loading @@ -119,13 +128,16 @@ public class MeasuredTextMemoryUsageTest { @Test public void testMemoryUsage_Hyphenatation_WidthOnly() { int[] memories = new int[TRIAL_COUNT]; // Report median of randomly generated MeasuredText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(false /* width only */).getMemoryUsage(); .build(); // Report median of randomly generated PrecomputedText. for (int i = 0; i < TRIAL_COUNT; ++i) { CharSequence cs = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); memories[i] = PrecomputedText.createWidthOnly(cs, param, 0, cs.length()) .getMemoryUsage(); } reportMemoryUsage(median(memories), "MemoryUsage_Hyphenation_WidthOnly"); } Loading apct-tests/perftests/core/src/android/text/MeasuredTextPerfTest.java→apct-tests/perftests/core/src/android/text/PrecomputedTextPerfTest.java +50 −34 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ import java.util.Random; @LargeTest @RunWith(AndroidJUnit4.class) public class MeasuredTextPerfTest { public class PrecomputedTextPerfTest { private static final int WORD_LENGTH = 9; // Random word has 9 characters. private static final int WORDS_IN_LINE = 8; // Roughly, 8 words in a line. private static final boolean NO_STYLE_TEXT = false; Loading @@ -51,7 +51,7 @@ public class MeasuredTextPerfTest { private static TextPaint PAINT = new TextPaint(); private static final int TEXT_WIDTH = WORDS_IN_LINE * WORD_LENGTH * (int) PAINT.getTextSize(); public MeasuredTextPerfTest() {} public PrecomputedTextPerfTest() {} @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); Loading @@ -66,120 +66,136 @@ public class MeasuredTextPerfTest { @Test public void testCreate_NoStyled_Hyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(true /* do full layout */); PrecomputedText.create(text, param); } } @Test public void testCreate_NoStyled_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(true /* do full layout */); PrecomputedText.create(text, param); } } @Test public void testCreate_NoStyled_Hyphenation_WidthOnly() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(false /* width only */); PrecomputedText.create(text, param); } } @Test public void testCreate_NoStyled_NoHyphenation_WidthOnly() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(false /* width only */); PrecomputedText.create(text, param); } } @Test public void testCreate_Styled_Hyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(true /* do full layout */); PrecomputedText.create(text, param); } } @Test public void testCreate_Styled_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(true /* do full layout */); PrecomputedText.create(text, param); } } @Test public void testCreate_Styled_Hyphenation_WidthOnly() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(false /* width only */); PrecomputedText.create(text, param); } } @Test public void testCreate_Styled_NoHyphenation_WidthOnly() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(false /* width only */); PrecomputedText.create(text, param); } } } apct-tests/perftests/core/src/android/text/StaticLayoutPerfTest.java +44 −42 Original line number Diff line number Diff line Loading @@ -63,6 +63,18 @@ public class StaticLayoutPerfTest { mTextUtil.resetRandom(0 /* seed */); } private PrecomputedText makeMeasured(CharSequence text, TextPaint paint) { PrecomputedText.Params param = new PrecomputedText.Params.Builder(paint).build(); return PrecomputedText.create(text, param); } private PrecomputedText makeMeasured(CharSequence text, TextPaint paint, int strategy, int frequency) { PrecomputedText.Params param = new PrecomputedText.Params.Builder(paint) .setHyphenationFrequency(frequency).setBreakStrategy(strategy).build(); return PrecomputedText.create(text, param); } @Test public void testCreate_FixedText_NoStyle_Greedy_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); Loading Loading @@ -151,15 +163,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_NoStyled_Greedy_NoHyphenation() { public void testCreate_PrecomputedText_NoStyled_Greedy_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_SIMPLE, Layout.HYPHENATION_FREQUENCY_NONE); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading @@ -170,15 +180,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_NoStyled_Greedy_Hyphenation() { public void testCreate_PrecomputedText_NoStyled_Greedy_Hyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_SIMPLE, Layout.HYPHENATION_FREQUENCY_NORMAL); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading @@ -189,15 +197,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_NoStyled_Balanced_NoHyphenation() { public void testCreate_PrecomputedText_NoStyled_Balanced_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_BALANCED, Layout.HYPHENATION_FREQUENCY_NONE); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading @@ -208,15 +214,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_NoStyled_Balanced_Hyphenation() { public void testCreate_PrecomputedText_NoStyled_Balanced_Hyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_BALANCED, Layout.HYPHENATION_FREQUENCY_NORMAL); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading @@ -227,15 +231,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_Styled_Greedy_NoHyphenation() { public void testCreate_PrecomputedText_Styled_Greedy_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_SIMPLE, Layout.HYPHENATION_FREQUENCY_NONE); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading Loading @@ -328,13 +330,13 @@ public class StaticLayoutPerfTest { } @Test public void testDraw_MeasuredText_Styled() { public void testDraw_PrecomputedText_Styled() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final RenderNode node = RenderNode.create("benchmark", null); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT).build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT); final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build(); final DisplayListCanvas c = node.start(1200, 200); Loading @@ -345,13 +347,13 @@ public class StaticLayoutPerfTest { } @Test public void testDraw_MeasuredText_NoStyled() { public void testDraw_PrecomputedText_NoStyled() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final RenderNode node = RenderNode.create("benchmark", null); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT).build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT); final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build(); final DisplayListCanvas c = node.start(1200, 200); Loading @@ -362,13 +364,13 @@ public class StaticLayoutPerfTest { } @Test public void testDraw_MeasuredText_Styled_WithoutCache() { public void testDraw_PrecomputedText_Styled_WithoutCache() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final RenderNode node = RenderNode.create("benchmark", null); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT).build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT); final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build(); final DisplayListCanvas c = node.start(1200, 200); Loading @@ -380,13 +382,13 @@ public class StaticLayoutPerfTest { } @Test public void testDraw_MeasuredText_NoStyled_WithoutCache() { public void testDraw_PrecomputedText_NoStyled_WithoutCache() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final RenderNode node = RenderNode.create("benchmark", null); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT).build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT); final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build(); final DisplayListCanvas c = node.start(1200, 200); Loading api/current.txt +28 −23 File changed.Preview size limit exceeded, changes collapsed. Show changes core/java/android/text/BoringLayout.java +2 −2 Original line number Diff line number Diff line Loading @@ -347,8 +347,8 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback TextLine line = TextLine.obtain(); line.set(paint, text, 0, textLength, Layout.DIR_LEFT_TO_RIGHT, Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null); if (text instanceof MeasuredText) { MeasuredText mt = (MeasuredText) text; if (text instanceof PrecomputedText) { PrecomputedText mt = (PrecomputedText) text; // Reaching here means there is only one paragraph. MeasuredParagraph mp = mt.getMeasuredParagraph(0); fm.width = (int) Math.ceil(mp.getWidth(0, mp.getTextLength())); Loading Loading
apct-tests/perftests/core/src/android/text/MeasuredTextMemoryUsageTest.java→apct-tests/perftests/core/src/android/text/PrecomputedTextMemoryUsageTest.java +34 −22 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ import java.util.Random; @LargeTest @RunWith(AndroidJUnit4.class) public class MeasuredTextMemoryUsageTest { public class PrecomputedTextMemoryUsageTest { private static final int WORD_LENGTH = 9; // Random word has 9 characters. private static final boolean NO_STYLE_TEXT = false; Loading @@ -53,7 +53,7 @@ public class MeasuredTextMemoryUsageTest { private static int TRIAL_COUNT = 100; public MeasuredTextMemoryUsageTest() {} public PrecomputedTextMemoryUsageTest() {} private TextPerfUtils mTextUtil = new TextPerfUtils(); Loading @@ -77,13 +77,16 @@ public class MeasuredTextMemoryUsageTest { @Test public void testMemoryUsage_NoHyphenation() { int[] memories = new int[TRIAL_COUNT]; // Report median of randomly generated MeasuredText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build().getMemoryUsage(); .build(); // Report median of randomly generated PrecomputedText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = PrecomputedText.create( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), param) .getMemoryUsage(); } reportMemoryUsage(median(memories), "MemoryUsage_NoHyphenation"); } Loading @@ -91,13 +94,16 @@ public class MeasuredTextMemoryUsageTest { @Test public void testMemoryUsage_Hyphenation() { int[] memories = new int[TRIAL_COUNT]; // Report median of randomly generated MeasuredText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build().getMemoryUsage(); .build(); // Report median of randomly generated PrecomputedText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = PrecomputedText.create( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), param) .getMemoryUsage(); } reportMemoryUsage(median(memories), "MemoryUsage_Hyphenation"); } Loading @@ -105,13 +111,16 @@ public class MeasuredTextMemoryUsageTest { @Test public void testMemoryUsage_NoHyphenation_WidthOnly() { int[] memories = new int[TRIAL_COUNT]; // Report median of randomly generated MeasuredText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(false /* width only */).getMemoryUsage(); .build(); // Report median of randomly generated PrecomputedText. for (int i = 0; i < TRIAL_COUNT; ++i) { CharSequence cs = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); memories[i] = PrecomputedText.createWidthOnly(cs, param, 0, cs.length()) .getMemoryUsage(); } reportMemoryUsage(median(memories), "MemoryUsage_NoHyphenation_WidthOnly"); } Loading @@ -119,13 +128,16 @@ public class MeasuredTextMemoryUsageTest { @Test public void testMemoryUsage_Hyphenatation_WidthOnly() { int[] memories = new int[TRIAL_COUNT]; // Report median of randomly generated MeasuredText. for (int i = 0; i < TRIAL_COUNT; ++i) { memories[i] = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(false /* width only */).getMemoryUsage(); .build(); // Report median of randomly generated PrecomputedText. for (int i = 0; i < TRIAL_COUNT; ++i) { CharSequence cs = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); memories[i] = PrecomputedText.createWidthOnly(cs, param, 0, cs.length()) .getMemoryUsage(); } reportMemoryUsage(median(memories), "MemoryUsage_Hyphenation_WidthOnly"); } Loading
apct-tests/perftests/core/src/android/text/MeasuredTextPerfTest.java→apct-tests/perftests/core/src/android/text/PrecomputedTextPerfTest.java +50 −34 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ import java.util.Random; @LargeTest @RunWith(AndroidJUnit4.class) public class MeasuredTextPerfTest { public class PrecomputedTextPerfTest { private static final int WORD_LENGTH = 9; // Random word has 9 characters. private static final int WORDS_IN_LINE = 8; // Roughly, 8 words in a line. private static final boolean NO_STYLE_TEXT = false; Loading @@ -51,7 +51,7 @@ public class MeasuredTextPerfTest { private static TextPaint PAINT = new TextPaint(); private static final int TEXT_WIDTH = WORDS_IN_LINE * WORD_LENGTH * (int) PAINT.getTextSize(); public MeasuredTextPerfTest() {} public PrecomputedTextPerfTest() {} @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); Loading @@ -66,120 +66,136 @@ public class MeasuredTextPerfTest { @Test public void testCreate_NoStyled_Hyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(true /* do full layout */); PrecomputedText.create(text, param); } } @Test public void testCreate_NoStyled_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(true /* do full layout */); PrecomputedText.create(text, param); } } @Test public void testCreate_NoStyled_Hyphenation_WidthOnly() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(false /* width only */); PrecomputedText.create(text, param); } } @Test public void testCreate_NoStyled_NoHyphenation_WidthOnly() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(false /* width only */); PrecomputedText.create(text, param); } } @Test public void testCreate_Styled_Hyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(true /* do full layout */); PrecomputedText.create(text, param); } } @Test public void testCreate_Styled_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(true /* do full layout */); PrecomputedText.create(text, param); } } @Test public void testCreate_Styled_Hyphenation_WidthOnly() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(false /* width only */); PrecomputedText.create(text, param); } } @Test public void testCreate_Styled_NoHyphenation_WidthOnly() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final PrecomputedText.Params param = new PrecomputedText.Params.Builder(PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); while (state.keepRunning()) { state.pauseTiming(); final CharSequence text = mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT); state.resumeTiming(); new MeasuredText.Builder(text, PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(false /* width only */); PrecomputedText.create(text, param); } } }
apct-tests/perftests/core/src/android/text/StaticLayoutPerfTest.java +44 −42 Original line number Diff line number Diff line Loading @@ -63,6 +63,18 @@ public class StaticLayoutPerfTest { mTextUtil.resetRandom(0 /* seed */); } private PrecomputedText makeMeasured(CharSequence text, TextPaint paint) { PrecomputedText.Params param = new PrecomputedText.Params.Builder(paint).build(); return PrecomputedText.create(text, param); } private PrecomputedText makeMeasured(CharSequence text, TextPaint paint, int strategy, int frequency) { PrecomputedText.Params param = new PrecomputedText.Params.Builder(paint) .setHyphenationFrequency(frequency).setBreakStrategy(strategy).build(); return PrecomputedText.create(text, param); } @Test public void testCreate_FixedText_NoStyle_Greedy_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); Loading Loading @@ -151,15 +163,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_NoStyled_Greedy_NoHyphenation() { public void testCreate_PrecomputedText_NoStyled_Greedy_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_SIMPLE, Layout.HYPHENATION_FREQUENCY_NONE); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading @@ -170,15 +180,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_NoStyled_Greedy_Hyphenation() { public void testCreate_PrecomputedText_NoStyled_Greedy_Hyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_SIMPLE, Layout.HYPHENATION_FREQUENCY_NORMAL); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading @@ -189,15 +197,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_NoStyled_Balanced_NoHyphenation() { public void testCreate_PrecomputedText_NoStyled_Balanced_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_BALANCED, Layout.HYPHENATION_FREQUENCY_NONE); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading @@ -208,15 +214,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_NoStyled_Balanced_Hyphenation() { public void testCreate_PrecomputedText_NoStyled_Balanced_Hyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_BALANCED) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_BALANCED, Layout.HYPHENATION_FREQUENCY_NORMAL); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading @@ -227,15 +231,13 @@ public class StaticLayoutPerfTest { } @Test public void testCreate_MeasuredText_Styled_Greedy_NoHyphenation() { public void testCreate_PrecomputedText_Styled_Greedy_NoHyphenation() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT) .setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE) .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE) .build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT, Layout.BREAK_STRATEGY_SIMPLE, Layout.HYPHENATION_FREQUENCY_NONE); state.resumeTiming(); StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH) Loading Loading @@ -328,13 +330,13 @@ public class StaticLayoutPerfTest { } @Test public void testDraw_MeasuredText_Styled() { public void testDraw_PrecomputedText_Styled() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final RenderNode node = RenderNode.create("benchmark", null); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT).build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT); final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build(); final DisplayListCanvas c = node.start(1200, 200); Loading @@ -345,13 +347,13 @@ public class StaticLayoutPerfTest { } @Test public void testDraw_MeasuredText_NoStyled() { public void testDraw_PrecomputedText_NoStyled() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final RenderNode node = RenderNode.create("benchmark", null); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT).build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT); final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build(); final DisplayListCanvas c = node.start(1200, 200); Loading @@ -362,13 +364,13 @@ public class StaticLayoutPerfTest { } @Test public void testDraw_MeasuredText_Styled_WithoutCache() { public void testDraw_PrecomputedText_Styled_WithoutCache() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final RenderNode node = RenderNode.create("benchmark", null); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT).build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT); final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build(); final DisplayListCanvas c = node.start(1200, 200); Loading @@ -380,13 +382,13 @@ public class StaticLayoutPerfTest { } @Test public void testDraw_MeasuredText_NoStyled_WithoutCache() { public void testDraw_PrecomputedText_NoStyled_WithoutCache() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); final RenderNode node = RenderNode.create("benchmark", null); while (state.keepRunning()) { state.pauseTiming(); final MeasuredText text = new MeasuredText.Builder( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT).build(); final PrecomputedText text = makeMeasured( mTextUtil.nextRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT); final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build(); final DisplayListCanvas c = node.start(1200, 200); Loading
core/java/android/text/BoringLayout.java +2 −2 Original line number Diff line number Diff line Loading @@ -347,8 +347,8 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback TextLine line = TextLine.obtain(); line.set(paint, text, 0, textLength, Layout.DIR_LEFT_TO_RIGHT, Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null); if (text instanceof MeasuredText) { MeasuredText mt = (MeasuredText) text; if (text instanceof PrecomputedText) { PrecomputedText mt = (PrecomputedText) text; // Reaching here means there is only one paragraph. MeasuredParagraph mp = mt.getMeasuredParagraph(0); fm.width = (int) Math.ceil(mp.getWidth(0, mp.getTextLength())); Loading