| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.text; |
| 18 |
|
| 19 |
import com.google.caliper.AfterExperiment; |
| 20 |
import com.google.caliper.BeforeExperiment; |
| 21 |
import com.google.caliper.Benchmark; |
| 22 |
import com.google.caliper.Param; |
| 23 |
|
| 24 |
public class SpannableStringInternalCopyBenchmark { |
| 25 |
|
| 26 |
@Param({"1", "4", "16"}) |
| 27 |
private String paramStringMult; |
| 28 |
|
| 29 |
private SpannedString spanned; |
| 30 |
|
| 31 |
@BeforeExperiment |
| 32 |
protected void setUp() throws Exception { |
| 33 |
int strSize = Integer.parseInt(paramStringMult); |
| 34 |
StringBuilder strBuilder = new StringBuilder(); |
| 35 |
for (int i = 0; i < strSize; i++) { |
| 36 |
strBuilder.append(SpannableStringBuilderBenchmark.TEST_STRING); |
| 37 |
} |
| 38 |
Spanned source = Html.fromHtml(strBuilder.toString()); |
| 39 |
spanned = new SpannedString(source); |
| 40 |
} |
| 41 |
|
| 42 |
@AfterExperiment |
| 43 |
protected void tearDown() { |
| 44 |
spanned = null; |
| 45 |
} |
| 46 |
|
| 47 |
@Benchmark |
| 48 |
public void timeCopyConstructor(int reps) throws Exception { |
| 49 |
for (int i = 0; i < reps; i++) { |
| 50 |
new SpannedString(spanned); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
@Benchmark |
| 55 |
public void timeSubsequence(int reps) throws Exception { |
| 56 |
for (int i = 0; i < reps; i++) { |
| 57 |
spanned.subSequence(1, spanned.length()-1); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
} |