/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.text; import com.google.caliper.AfterExperiment; import com.google.caliper.BeforeExperiment; import com.google.caliper.Benchmark; import com.google.caliper.Param; public class SpannableStringBuilderBenchmark { @Param({"android.text.style.ImageSpan", "android.text.style.ParagraphStyle", "android.text.style.CharacterStyle", "java.lang.Object"}) private String paramType; @Param({"1", "4", "16"}) private String paramStringMult; private Class clazz; private SpannableStringBuilder builder; @BeforeExperiment protected void setUp() throws Exception { clazz = Class.forName(paramType); int strSize = Integer.parseInt(paramStringMult); StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < strSize; i++) { strBuilder.append(TEST_STRING); } builder = new SpannableStringBuilder(Html.fromHtml(strBuilder.toString())); } @AfterExperiment protected void tearDown() { builder.clear(); builder = null; } @Benchmark public void timeGetSpans(int reps) throws Exception { for (int i = 0; i < reps; i++) { builder.getSpans(0, builder.length(), clazz); } } //contains 0 ImageSpans, 2 ParagraphSpans, 53 CharacterStyleSpans public static String TEST_STRING = "

some link

\n" + "

some title

\n" + "

by some name\n" + " some text

\n" + "

some date

\n" + "\n" + " \n" + "
\n" + "

a paragraph

\n" + "
\n" + "

" + "some header two

\n" + "

Lorem ipsum dolor concludaturque.

\n" + "


\n" + "

Vix te doctus

\n" + "

Error mel, est ei. " + "asda ullamcorper eam.

\n" + "

adversarium efficiantur, " + "mea te.

\n" + "


\n" + "

Testing display of HTML elements

\n" + "

2nd level heading

\n" + "

test paragraph.

\n" + "

3rd level heading

\n" + "

test paragraph.

\n" + "

4th level heading

\n" + "

test paragraph.

\n" + "
5th level heading
\n" + "

test paragraph.

\n" + "
6th level heading
\n" + "

test paragraph.

\n" + "

level elements

\n" + "

a normap paragraph(p element).\n" + " with some strong.

\n" + "
This is a div element.
\n" + "

This is a block quotation with some style

\n" + "
an address element
\n" + "

Text-level markup

\n" + "\n"; }