/* * 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 = "
\n" + "some date
\n" + "\n" +
"
|
Lorem ipsum dolor concludaturque.
\n" + "Vix te doctus
\n" + "Error mel, est ei. " + "asda ullamcorper eam.
\n" + "adversarium efficiantur, " + "mea te.
\n" + "test paragraph.
\n" + "test paragraph.
\n" + "test paragraph.
\n" + "test paragraph.
\n" + "test paragraph.
\n" + "a normap paragraph(p
element).\n" +
" with some strong.
div
element. \n" + "an address element\n" + "This is a block quotation with some style
abbr
markup used)\n" +
" a[i] = b[i] + c[i);
\n" +
" Hello!\n" + "
She said\n" + "Hello!
sub
and\n" +
" sup
x1 and H2O\n" +
" Mlle, 1st, ex, sin2 x,\n" +
" ex2 and f(x)g(x)a+b+c\n" +
" (where 2 and a+b+c should appear as exponents of exponents).\n" +
" cat
filename displays the\n" +
" the filename.\n" +
"