Java Code Examples for android.perftests.utils.PerfStatusReporter

Following code examples demonstrate how to use android.perftests.utils.PerfStatusReporterfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use android.perftests.utils.PerfStatusReporterand various code implementation of this class.

    public void testConstruction() throws Throwable {
        final Context context = InstrumentationRegistry.getTargetContext();
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final LayoutInflater inflator =
                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        while (state.keepRunning()) {
            inflator.inflate(mLayoutId, null, false);
        }
    } 


    public void testLogPerf() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        int i = 0;
        while (state.keepRunning()) {
            Log.d("LogPerfTest", strings[(i++) % strings.length]);
        }
    } 

    public void testSetEmpty() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        Outline outline = new Outline();
        while (state.keepRunning()) {
            outline.setEmpty();
        }
    } 

    public void testSetRoundRect() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        Outline outline = new Outline();
        while (state.keepRunning()) {
            outline.setRoundRect(50, 50, 150, 150, 5);
        }
    } 

    public void timeCachedGetSharedPreferences() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final Context context = InstrumentationRegistry.getTargetContext();
        SharedPreferences prefs = context.getSharedPreferences("test", Context.MODE_PRIVATE);
        while (state.keepRunning()) {
            prefs = context.getSharedPreferences("test", Context.MODE_PRIVATE);
        }
    } 

    public void testGetAccounts() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final Context context = InstrumentationRegistry.getTargetContext();
        if (context.checkSelfPermission(Manifest.permission.GET_ACCOUNTS)
                != PackageManager.PERMISSION_GRANTED) {
            fail("Missing required GET_ACCOUNTS permission");
        }
        AccountManager accountManager = AccountManager.get(context);
        while (state.keepRunning()) {
            accountManager.getAccounts();
        }
    } 

    public void testSimpleViewInflate() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
        LayoutInflater inflater = LayoutInflater.from(context);
        FrameLayout root = new FrameLayout(context);
        while (state.keepRunning()) {
            inflater.inflate(R.layout.test_simple_view, root, false);
        }
    } 

    public void testTwelveKeyInflate() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
        LayoutInflater inflater = LayoutInflater.from(context);
        FrameLayout root = new FrameLayout(context);
        while (state.keepRunning()) {
            inflater.inflate(R.layout.twelve_key_entry, root, false);
        }
    } 

    public void testHasGlyph() {
        Paint paint = new Paint();
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            paint.hasGlyph(mQuery);
        }
    } 

    public void testPss() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        while (state.keepRunning()) {
            Debug.getPss();
        }
    } 

Advertisement
Javadoc
Use this rule to make sure we report the status after the test success. @Rule public PerfStatusRepo

rter mPerfStatusReporter = new PerfStatusReporter(); @Test public void functionName() { ... BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { // DO YOUR TEST HERE! ... When test succeeded, the status report will use the key as "functionName[optional subTestName]_ " Notice that optional subTestName can't be just numbers, that means each sub test needs to have a name when using parameterization.

Read More
Related Classes
Advertisement