Java Code Examples for android.perftests.utils.BenchmarkState

Following code examples demonstrate how to use android.perftests.utils.BenchmarkStatefrom 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.BenchmarkStateand various code implementation of this class.

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


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

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

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

    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 testPss() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        while (state.keepRunning()) {
            Debug.getPss();
        }
    } 

Advertisement
Javadoc
Provides a benchmark framework. Example usage: // Executes the code while keepRunning returning true

. public void sampleMethod() { BenchmarkState state = new BenchmarkState(); int[] src = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ; while (state.keepRunning()) { int[] dest = new int[src.length]; System.arraycopy(src, 0, dest, 0, src.length); System.out.println(state.summaryLine());

Read More
Related Classes
Advertisement