| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import android.perftests.utils.BenchmarkState; |
| 20 |
import android.perftests.utils.PerfStatusReporter; |
| 21 |
|
| 22 |
import androidx.test.filters.LargeTest; |
| 23 |
|
| 24 |
import org.junit.Rule; |
| 25 |
import org.junit.Test; |
| 26 |
import org.junit.runner.RunWith; |
| 27 |
import org.junit.runners.Parameterized; |
| 28 |
|
| 29 |
import java.util.Arrays; |
| 30 |
import java.util.Collection; |
| 31 |
|
| 32 |
@LargeTest |
| 33 |
@RunWith(Parameterized.class) |
| 34 |
public class ParcelStringPerfTest { |
| 35 |
@Rule |
| 36 |
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); |
| 37 |
|
| 38 |
@Parameterized.Parameter(0) |
| 39 |
public String mName; |
| 40 |
@Parameterized.Parameter(1) |
| 41 |
public String mValue; |
| 42 |
|
| 43 |
@Parameterized.Parameters(name = "{0}") |
| 44 |
public static Collection<Object[]> getParameters() { |
| 45 |
return Arrays.asList(new Object[][] { |
| 46 |
{ "simple", "com.example.typical_package_name" }, |
| 47 |
{ "complex", "從不喜歡孤單一個 - 蘇永康/吳雨霏" }, |
| 48 |
}); |
| 49 |
} |
| 50 |
|
| 51 |
@Test |
| 52 |
public void timeWriteString8() { |
| 53 |
final Parcel parcel = Parcel.obtain(); |
| 54 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 55 |
while (state.keepRunning()) { |
| 56 |
parcel.setDataPosition(0); |
| 57 |
parcel.writeString8(mValue); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
@Test |
| 62 |
public void timeWriteString16() { |
| 63 |
final Parcel parcel = Parcel.obtain(); |
| 64 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 65 |
while (state.keepRunning()) { |
| 66 |
parcel.setDataPosition(0); |
| 67 |
parcel.writeString16(mValue); |
| 68 |
} |
| 69 |
} |
| 70 |
} |